Skip to content

assign

js
_.assign(object, [sources])

将源对象的自身可枚举字符串键属性分配给目标对象。源对象从左到右应用。后续源将覆盖先前源的属性分配。

¥Assigns own enumerable string keyed properties of source objects to the destination object. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.

注意:此方法改变 object,并大致基于 Object.assign

¥Note: This method mutates object and is loosely based on Object.assign.

新增于

¥Since

0.10.0

参数

¥Arguments

  1. object (对象):目标对象。

    ¥object (Object): The destination object.

  2. [sources] (...对象):起始位置。

    ¥[sources] (...Object): The source objects.

返回

¥Returns

(对象):返回 object

¥(Object): Returns object.

示例

¥Example

js
function Foo() {
  this.a = 1;
}

function Bar() {
  this.c = 3;
}

Foo.prototype.b = 2;
Bar.prototype.d = 4;

_.assign({ 'a': 0 }, new Foo, new Bar);
// => { 'a': 1, 'c': 3 }

Lodash v4.17 中文网 - 粤ICP备13048890号