mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 14:37:49 +00:00
40 lines
1003 B
JavaScript
40 lines
1003 B
JavaScript
import copyObject from './_copyObject';
|
|
import createAssigner from './_createAssigner';
|
|
import keys from './keys';
|
|
|
|
/**
|
|
* Assigns own enumerable properties of source objects to the destination
|
|
* object. Source objects are applied from left to right. Subsequent sources
|
|
* overwrite property assignments of previous sources.
|
|
*
|
|
* **Note:** This method mutates `object` and is loosely based on
|
|
* [`Object.assign`](https://mdn.io/Object/assign).
|
|
*
|
|
* @static
|
|
* @memberOf _
|
|
* @category Object
|
|
* @param {Object} object The destination object.
|
|
* @param {...Object} [sources] The source objects.
|
|
* @returns {Object} Returns `object`.
|
|
* @example
|
|
*
|
|
* function Foo() {
|
|
* this.c = 3;
|
|
* }
|
|
*
|
|
* function Bar() {
|
|
* this.e = 5;
|
|
* }
|
|
*
|
|
* Foo.prototype.d = 4;
|
|
* Bar.prototype.f = 6;
|
|
*
|
|
* _.assign({ 'a': 1 }, new Foo, new Bar);
|
|
* // => { 'a': 1, 'c': 3, 'e': 5 }
|
|
*/
|
|
var assign = createAssigner(function(object, source) {
|
|
copyObject(source, keys(source), object);
|
|
});
|
|
|
|
export default assign;
|