methods - Obtain property name within anonymous function in Javascript -


is possible name of property called anonymous function in javascript?

example

var obj = {      whoami: function() {        //obtain name whoami      } } 

the function has no (direct) idea name of property or variable references it.

though depending on means of invocation, discovered.

var obj = {      whoami: function func() {          (var p in this)              if (this[p] === func)                  alert(p);      } }  obj.whoami(); 

demo: http://jsfiddle.net/wudnf/

this works if function invoked this set object referencing it.

you use arguments.callee instead of giving function name, though that's not permitted in strict mode.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -