在 Javascript 严格模式下
Deleting an undeletable property is not allowed
要确保不删除这样一个不可删除的属性,如何确定property X 是可删除的,property Y 是不可删除的
背后的概念是……?
最佳答案
The concept behind this is...?
Property attributes .每个将其 configurable
属性设置为 false
的属性都不能被delete
d(在草率模式下静默失败并在严格模式下抛出)。
How to figure out whether a property is deletable?
您可以使用 Object.getOwnPropertyDescriptor()
function将属性作为对象访问:
var isDeletable = Object.getOwnPropertyDescriptor(obj, "propName").configurable;
请注意,这仅适用于 obj
的自身属性,不适用于继承的属性;对于那些你必须调用相应原型(prototype)上的函数。
关于javascript - 如何识别javascript不可删除的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34357752/