You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

7 years ago
  1. # object-assign [![Build Status](https://travis-ci.org/sindresorhus/object-assign.svg?branch=master)](https://travis-ci.org/sindresorhus/object-assign)
  2. > ES2015 [`Object.assign()`](http://www.2ality.com/2014/01/object-assign.html) ponyfill
  3. > Ponyfill: A polyfill that doesn't overwrite the native method
  4. ## Install
  5. ```
  6. $ npm install --save object-assign
  7. ```
  8. ## Usage
  9. ```js
  10. const objectAssign = require('object-assign');
  11. objectAssign({foo: 0}, {bar: 1});
  12. //=> {foo: 0, bar: 1}
  13. // multiple sources
  14. objectAssign({foo: 0}, {bar: 1}, {baz: 2});
  15. //=> {foo: 0, bar: 1, baz: 2}
  16. // overwrites equal keys
  17. objectAssign({foo: 0}, {foo: 1}, {foo: 2});
  18. //=> {foo: 2}
  19. // ignores null and undefined sources
  20. objectAssign({foo: 0}, null, {bar: 1}, undefined);
  21. //=> {foo: 0, bar: 1}
  22. ```
  23. ## API
  24. ### objectAssign(target, source, [source, ...])
  25. Assigns enumerable own properties of `source` objects to the `target` object and returns the `target` object. Additional `source` objects will overwrite previous ones.
  26. ## Resources
  27. - [ES2015 spec - Object.assign](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign)
  28. ## Related
  29. - [deep-assign](https://github.com/sindresorhus/deep-assign) - Recursive `Object.assign()`
  30. ## License
  31. MIT © [Sindre Sorhus](https://sindresorhus.com)