Last active
July 24, 2016 02:11
-
-
Save rhom6us/b80b68d4bdb15c5dbdfcf8591f0468be to your computer and use it in GitHub Desktop.
Map.prototype.toObject
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
/** | |
* This will be an instance member, Observable#publish. | |
* @memberof Map.prototype | |
* @param {Object} [target] - The object that the properties derived from the map's key/value pairs will be created on. | |
* @returns {Object} | |
*/ | |
Map.prototype.toObject = function(target = Object.create(null)) { | |
let props = [...this].map(kvp => { | |
let [key, value] = kvp; | |
return { | |
[key]: { | |
enumerable: true, | |
value: value, | |
writable: true | |
} | |
}; | |
}).reduce((a,b) => Object.assign(a,b)); | |
return Object.defineProperties(target, props); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment