实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
    <title>Data Properties Example</title>
5
    <script type="text/javascript">
6
7
        var person = {};
8
        Object.defineProperty(person, "name", {
9
            writable: false,
10
            value: "Nicholas"
11
        });
12
        
13
        alert(person.name);
14
        person.name = "Michael";
15
        alert(person.name);
16
17
18
    </script>
19
</head>
20
<body>
21
    <p>Note: this example only works in browsers that have implemented the ECMAScript 5 <code>Object.defineProperty()</code> method (IE9 and Firefox 4).</p>
22
</body>
23
</html>