Skip to content

Instantly share code, notes, and snippets.

@Kambfhase
Created December 6, 2010 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kambfhase/730792 to your computer and use it in GitHub Desktop.
Save Kambfhase/730792 to your computer and use it in GitHub Desktop.
Syntactic saccharin
// 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