You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • 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)
    
About

Avatar for Gordon @Gordon started