Hmm, that's a tricky one - yes function.name isn't implemented. It's a bit tricky because to do it you'd end up having to waste a variable on every function to store the name twice. For instance this is what happens in Node:
> var a = function() {}
undefined
> a.name
'a'
> var b = a;
undefined
> b.name
'a'
If all the functions you care about are in the global scope, you could run some code like this that adds name. It won't be fast but it'll work:
function hello() {
}
Object.defineProperty(Function.prototype, "name", {
get : function(){
for (var k in global)
if (global[k] == this) return k;
}});
print(hello.name)
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hmm, that's a tricky one - yes
function.name
isn't implemented. It's a bit tricky because to do it you'd end up having to waste a variable on every function to store the name twice. For instance this is what happens in Node:If all the functions you care about are in the global scope, you could run some code like this that adds
name
. It won't be fast but it'll work: