Skip to content

Instantly share code, notes, and snippets.

@mattbaker
Created June 14, 2011 18:54
Show Gist options
  • Select an option

  • Save mattbaker/1025583 to your computer and use it in GitHub Desktop.

Select an option

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);
@mattbaker

mattbaker commented Oct 6, 2011 via email

Copy link
Copy Markdown
Author

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