来自节点repl:
foo = { bar: 'baz'};
console.log (Object.getOwnPropertyDescriptor(foo, 'bar'))
返回值:
{ value: 'baz',
writable: true,
enumerable: true,
configurable: true }
如何将 writable enumerable 和 configurable 更改为 false?这些值叫什么?它们是 ES5.1 的一部分吗?还有repl没有输出的吗?
最佳答案
"How do you change the writable enumerable, and configurable to false?"
Object.defineProperty(foo, 'baz', {
enumerable:false,
writable:false,
configurable:false
});
还有 Object.defineProperties
和 Object.create
是一样的,只是你可以设置多个属性,它让你创建一个新对象,并设置它的原型(prototype)对象及其描述符。
"What are these values called?"
它们是属性描述符。
"Are they part of ES5.1?"
是的,ES5。
"Are there more that the repl didn't output?"
还有什么,属性描述符?没有。
关于javascript - 如何更改 Javascript 对象属性的可写可枚举和可配置值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11279177/