Created
July 8, 2016 09:24
-
-
Save bendc/e1dc2087c2db3a7bfd72f19f54fc87ea to your computer and use it in GitHub Desktop.
Friendlier object definition
This file contains hidden or 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
const define = (object, ...pairs) => | |
(Array.isArray(pairs[0]) ? pairs : [pairs]).reduce((accumulator, pair) => { | |
const [ key, value ] = pair; | |
return Object.defineProperty(accumulator, key, { value, enumerable: true }); | |
}, object); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: