I’m using Google Chrome 16.0.912.63 and have the following code:
__defineGetter__('x', function(){
console.log('In Getter: x'); return 1;
});
__defineGetter__('undefined', function(){
console.log('In Getter: undefined'); return 2;
});
console.log(x);
console.log(undefined);
The getter function for x is entered correctly, but the getter for undefined is never entered. The output logged to my console is:
In Getter: x
1
undefined
I was always under the impression that undefined behaves the same as any other global variable. I know that statements such as
undefined = 10;
undefined = null;
undefined = 'defined';
Are all valid, so what is different about undefined that makes it unable to have a getter (at least in my browser).
It doesn’t behave like any normal variable, it just pretends to, at least on Firefox and Chrome. Try it:
It’s more like a readonly property but doesn’t throw an error when it’s written to.