Created
November 15, 2012 20:50
-
-
Save evilbuck/4081178 to your computer and use it in GitHub Desktop.
javascript implementation of Ruby 1.9's tap
This file contains hidden or 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
Object.defineProperty(Object.prototype, 'tap', { | |
value: function(fun){ | |
fun.call( this ); | |
return this; | |
}, | |
enumerable: false | |
}); | |
// Usage: | |
// a = []; | |
// a.tap(function(){ this.push('foo'); }); | |
// a => [ 'foo' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ahh. Yes. I think I remember implementing it incorrectly after the fact when I typed this up 8 years ago. Thanks for the feedback. I'll need to look up how Ruby tap works again. I haven't used ruby in about 5 years.