Skip to content

Instantly share code, notes, and snippets.

@mattbaker
Created June 14, 2011 18:54
Show Gist options
  • Save mattbaker/1025583 to your computer and use it in GitHub Desktop.
Save mattbaker/1025583 to your computer and use it in GitHub Desktop.
Object.tap in Javascript
Object.prototype.tap = function(f){f.apply(this); return this;}
var x = {a:2};
x.tap(function(){console.log(this.a)}).a = 4; //Prints 2
console.assert(x.a == 4);
@nowhereman
Copy link

FYI, I've merged your code with another one and make a little demo at https://gist.github.com/1267298.
To run it: You need to download the HTML gist and open it in your browser.

@mattbaker
Copy link
Author

mattbaker commented Oct 6, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment