实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
    <title>Prototype Pattern Example</title>
5
    <script type="text/javascript">
6
            
7
        function Person(){
8
        }
9
        
10
        Person.prototype = {
11
            name : "Nicholas",
12
            age : 29,
13
            job: "Software Engineer",
14
            sayName : function () {
15
                alert(this.name);
16
            }
17
        };
18
19
        var friend = new Person();
20
        
21
        alert(friend instanceof Object);  //true
22
        alert(friend instanceof Person);  //true
23
        alert(friend.constructor == Person);  //false
24
        alert(friend.constructor == Object);  //true
25
        
26
    </script>
27
</head>
28
<body>
29
30
</body>
31
</html>