Lodash _.assignIn()方法就好像的_.assign()方法,但会迭代它的拥有和继承的源属性。 后续源对象将覆盖先前源的属性分配。该方法变异物体。
用法:
_.assignIn( dest_object, [src_obj])
参数: 此方法接受上面提到和下面描述的两个参数:
- dest_object:这是目标对象。
- src_obj:这些是源对象。
返回值:该方法返回一个对象。
范例1:
Javascript
// Defining Lodash variable
const _ = require('lodash');
function Gfg1() {
this.a = 1;
}
function Gfg2() {
this.c = 3;
}
Gfg1.prototype.b = 10;
Gfg2.prototype.d = 40;
console.log(_.assignIn( { a:4 },
new Gfg1, new Gfg2));输出:
{ a:1, b:10, c:3, d:40 }
范例2:
Javascript
// Defining Lodash variable
const _ = require('lodash');
function Gfg1() {
this.a = 1;
}
function Gfg2() {
this.c = 3;
}
console.log(_.assignIn( { a:4 },
new Gfg1, new Gfg2));输出:
{ a:1, c:3 }
相关用法
- Lodash _.method()用法及代码示例
- Lodash _.sneq()用法及代码示例
- Lodash _.toQuery()用法及代码示例
- Lodash _.uniqWith()用法及代码示例
- Lodash _.xorWith()用法及代码示例
- Lodash _.head()用法及代码示例
- Lodash _.remove()用法及代码示例
- Lodash _.pullAt()用法及代码示例
- Lodash _.pullAll()用法及代码示例
- Lodash _.pull()用法及代码示例
- Lodash _.nth()用法及代码示例
- Lodash _.takeRight()用法及代码示例
- Lodash _.take()用法及代码示例
- Lodash _.sortedLastIndex()用法及代码示例
- Lodash _.fromPairs()用法及代码示例
- Lodash _.differenceWith()用法及代码示例
- Lodash _.castArray()用法及代码示例
- Lodash _.cloneDeep()用法及代码示例
- Lodash _.clone()用法及代码示例
- Lodash _.sampleSize()用法及代码示例
- Lodash _.find()用法及代码示例
- Lodash _.zipWith()用法及代码示例
- Lodash _.zipObject()用法及代码示例
- Lodash _.xor()用法及代码示例
注:本文由纯净天空筛选整理自taran910大神的英文原创作品 Lodash _.assignIn() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
