Whether you can alias something depends on the data type. Objects, arrays, and functions will be handled by reference and aliasing is possible. Other types are essentially atomic, and the variable stores the value rather than a reference to a value.
arguments.callee is a function, and therefore you can have a reference to it and modify that shared object.
function foo() {
var self = arguments.callee;
self.myStaticVar = self.myStaticVar || 0;
self.myStaticVar++;
return self.myStaticVar;
}
Note that if in the above code you were to say self = function() {return 42;};
then self
would then 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 reference, it does not change the referred object. With atomic values, a case like y++
is equivalent to y = y + 1
, which is assigning a 'new' integer to the variable.