javascript - Access function propertes (.caller) without specifying it's own name -


in javascript can access function's "functional properties", instance caller. (actually, not know if "functional property" right word.)

for example:

func0 = function() {    console.log(typeof func0.caller) } func1 = func0 func1() var o = { func2: func0, func3: function(){ console.log(typeof o.func3.caller) } } o.func2() o.func3() 

as can see, must provide function name before can add .caller. if function anonymous or reason not want use name (maybe plan rename fucntion in future): can still access caller?

what accessing arguments object 'assigned' every function. don't use function name. use arguments object.

arguments object acts array, arguments[0] returns first argument passed function.

arguments.length  // property of arguments object tells how many arguments function has  arguments.caller // reference function invoked current function.  arguments.callee() call function recursively. reference executing function. 

is mean?

use arguments.callee.caller 

it seems reason works because arguments.callee giving reference function executing, , arguments.caller referencing function invoked function (which same function). maybe why using arguments.caller not advisable.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -