Skip to content

Instantly share code, notes, and snippets.

@rhom6us
Last active July 24, 2016 02:11
Show Gist options
  • Save rhom6us/b80b68d4bdb15c5dbdfcf8591f0468be to your computer and use it in GitHub Desktop.
Save rhom6us/b80b68d4bdb15c5dbdfcf8591f0468be to your computer and use it in GitHub Desktop.
Map.prototype.toObject
/**
* 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