把configurable 设置为false,表示不能从对象中删除属性

2017-06-21 10:21:00
admin
原创
450
<!DOCTYPE html>
<html>
<head>
    <title>Data Properties Example</title>
    <script type="text/javascript">

        var person = {};
        Object.defineProperty(person, "name", {
            configurable: false,
            value: "Nicholas"
        });
        
        alert(person.name);
        delete person.name;
        alert(person.name);

    </script>
</head>
<body>
    <p>Note: this example only works in browsers that have implemented the ECMAScript 5 <code>Object.defineProperty()</code> method (IE9 and Firefox 4).</p>
</body>
</html>
  • QQ讨论群
  • 关注微信
    • 欢迎咨询
    • 欢迎加入QQ群 16506021
  • 公众号:源宝网络