If you can alias, then something depends on the data type. Objects, arrays and functions will be processed using the link, and pseudonization is possible. Other types are essentially atomic, and the variable stores the value, not a reference to the value.
arguments.callee is a function, so you can reference it and modify this shared object.
function foo() { var self = arguments.callee; self.myStaticVar = self.myStaticVar || 0; self.myStaticVar++; return self.myStaticVar; }
Please note that if in the above code you should have said self = function() {return 42;}; , then self will refer to a different object than arguments.callee , which remains a reference to foo . When you have a compound object, the assignment operator replaces the link; it does not change the mentioned object. With atomic values, a case like y++ is equivalent to y = y + 1 , which sets the variable to "new."
Justin Love Nov 06 '09 at 12:11 2009-11-06 12:11
source share