js:Object.setPrototypeOf(obj1,obj2)设置原型

将obj1原型设置为obj2,obj1即可通过原型访对象obj2的属性

var obj1 = {a:"asfssdf",b:121111,c:[1,2,3]};
var obj2 = {d:["sdf",111,"ok"],e:999};
Object.setPrototypeOf(obj1,obj2);//将obj1原型设置为obj2
for(item in obj1){console.log(item)}//a b c d e
js:Object.setPrototypeOf(obj1,obj2)设置原型_第1张图片
image.png

你可能感兴趣的:(js:Object.setPrototypeOf(obj1,obj2)设置原型)