How to identify javascript undeletable properties? - Stack Overflow

In Javascript strict modeDeleting an undeletable property is not allowedTo make sure that one do not de

In Javascript strict mode

Deleting an undeletable property is not allowed

To make sure that one do not delete such an undeletable property, how do one figure out property X is deletable and property Y is undeletable

The concept behind it is......?

In Javascript strict mode

Deleting an undeletable property is not allowed

To make sure that one do not delete such an undeletable property, how do one figure out property X is deletable and property Y is undeletable

The concept behind it is......?

Share Improve this question asked Dec 18, 2015 at 14:24 Mr.XMr.X 31.4k27 gold badges147 silver badges229 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

The concept behind this is...?

Property attributes. Every property that has its configurable attribute set to false cannot be deleted (which fails silently in sloppy mode and throws in strict mode).

How to figure out whether a property is deletable?

You can use the Object.getOwnPropertyDescriptor() function to access the attributes as an object:

var isDeletable = Object.getOwnPropertyDescriptor(obj, "propName").configurable;

Notice that this will only work for own properties of obj, not inherited ones; for those you will have to call the function on the respective prototype.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745660141a4638785.html

相关推荐

  • How to identify javascript undeletable properties? - Stack Overflow

    In Javascript strict modeDeleting an undeletable property is not allowedTo make sure that one do not de

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信