Skip to content

Instantly share code, notes, and snippets.

@AndyHoang
Created February 18, 2016 10:22
Show Gist options
  • Save AndyHoang/64b0d7c59316adfdc42f to your computer and use it in GitHub Desktop.
Save AndyHoang/64b0d7c59316adfdc42f to your computer and use it in GitHub Desktop.
map for object
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;
}
});
@AndyHoang
Copy link
Author

looking for other way do not effect to Object.prototype

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