Skip to content

Instantly share code, notes, and snippets.

@MaxPleaner
Forked from mattbaker/object.prototype.js
Created July 19, 2017 19:50
Show Gist options
  • Save MaxPleaner/4735f9aefc0076a177c918557f28e534 to your computer and use it in GitHub Desktop.
Save MaxPleaner/4735f9aefc0076a177c918557f28e534 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment