var a = {};
Object.defineProperty(a, 'x', { value: 42, enumerable: true, configurable: true });
var b = Object.create(a);
b.x = 50;
console.log(b.x); // 10
console.log(b.hasOwnProperty('x')); //false

如图所示,当Object.create 函数使用了a对象为原型对象,创建新对象b的时候,由于a对象中的x属性是不可写的( writable默认为false ),造成的结果是b对象只能获取到原型上的属性x,而不能对b对象自身赋值x,为什么?(使用的是chrome浏览器),请大神们帮忙解惑,万分感谢
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
走同样的路,发现不同的人生