Object.assign()
复制一个访问器属性最终会转换为一个数据属性
var receiver = {}
var supplier= {
get name(){
return "holle world"
}
}
Object.assign(receiver,supplier)
receiver
{name: "holle world"}
receiver.name
"holle world"
supplier.name
"holle world"
var descriptor = Object.getOwnPropertyDescriptor(receiver,"name")
descriptor
{value: "holle world", writable: true, enumerable: true, configurable: true}configurable: trueenumerable: truevalue: "holle world"writable: true__proto__: Object
var descriptor1 = Object.getOwnPropertyDescriptor(supplier,"name")
descriptor1
{set: undefined, enumerable: true, configurable: true, get: ƒ}configurable: trueenumerable: trueget: ƒ name()set: undefined__proto__: Object
网友评论