Created
February 18, 2016 10:22
-
-
Save AndyHoang/64b0d7c59316adfdc42f to your computer and use it in GitHub Desktop.
map for object
This file contains 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, 'map', { | |
value: function(f, ctx) { | |
ctx = ctx || this; | |
var self = this, result = {}; | |
Object.keys(self).forEach(function(k) { | |
result[k] = f.call(ctx, self[k], k, self); | |
}); | |
return result; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
looking for other way do not effect to Object.prototype