<script type="text/javascript">
var f = function() {
this.x = '1';
alert(this.s); // undefined
}
f.s = '2';
f();
alert(f.s); // the value's there
alert(f.x); // undefined
</script>
I seem able to keep properties in an object instantiated with a function but I can’t access them from the function, nor can I access function variables from the outside either… is there some special trick to pierce the veil?
thisrefers to the context in which the function was called, not the function itself.You’re looking for
arguments.callee, which refers to the currently executing function.