Quote:
|
And it falls nowhere in scope -- it's in the global namespace
|
Indeed. I had to re-read the docs to remember that var only scopes a variable if declared within a function, quite unlike most (if not all) other languages. That was my bad. But how 'bout this one.
Code:
Array.prototype.push = function()
{
var arg, i = 0;
while( arg = arguments[i++] )
{
this[this.length] = arg;
}
return this.length;
}
What if you wanted to push onto the array the undefined value, null, or even the number 0?
...just keeping you on your toes.