Skip to content

assignIn

js
_.assignIn(object, [sources])

此方法与 _.assign 类似,不同之处在于它迭代自身和继承的源属性。

¥This method is like _.assign except that it iterates over own and inherited source properties.

注意:此方法改变 object

¥Note: This method mutates object.

新增于

¥Since

4.0.0

别名

¥Aliases

_.extend

参数

¥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;

_.assignIn({ 'a': 0 }, new Foo, new Bar);
// => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }

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