Skip to content

Instantly share code, notes, and snippets.

@dbani-dev
Forked from bendc/define.js
Created July 10, 2016 13:54
Show Gist options
  • Save dbani-dev/ef0872f5f58e4f046b5b516445e8632c to your computer and use it in GitHub Desktop.
Save dbani-dev/ef0872f5f58e4f046b5b516445e8632c to your computer and use it in GitHub Desktop.
Friendlier object definition
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