What is difference between creating object using Object.create() and Object.assign()?

前端 未结 3 1352
春和景丽
春和景丽 2020-12-13 09:49

Considering following code:

var obj1 = Object.create({}, {myProp: {value: 1}});
var obj2 = Object.assign({}, {myProp: 1});

Is there any dif

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 10:28

    Object.assign() provides shallow copying (Only properties and methods) and it will override the method and property declared.

    while Object.create() provides Deep copying provides prototype chain.

提交回复
热议问题