Created
May 30, 2016 08:09
-
-
Save danielronnkvist/aba9103e44770b4e2298c039662b7b29 to your computer and use it in GitHub Desktop.
Simple map function for JS objects.
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
/* | |
Use like | |
{key: "value"}.map((object, key) => { console.log(key) }) | |
*/ | |
if (typeof Object.prototype.map != 'function') { | |
Object.prototype.map = function(callback) { | |
'use strict'; | |
if (this == null) { | |
throw new TypeError('Cannot convert undefined or null to object'); | |
} | |
var target = Object(this); | |
return Object.keys(target).map(callback.bind(this, target)); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment