Created
December 6, 2010 19:37
-
-
Save Kambfhase/730792 to your computer and use it in GitHub Desktop.
Syntactic saccharin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Syntactic saccharin in JavaScript | |
// | |
// C-Hackers know that array[i] == *(i+array) == i[array] | |
// now lets have that in JavaScript, too! | |
(function(){ | |
var stack=[], str="[[getStack]]"; | |
Object.defineProperty( Number.prototype, str, { | |
get: function(){ | |
return stack.pop()[ +this]; | |
}, | |
configurable: true | |
}); | |
Array.prototype.toString=function(){ | |
stack.push( this); | |
return str; | |
} | |
Array.stack=stack; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment