实例代码“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
            constructor: Person,
12
            name : "Nicholas",
13
            age : 29,
14
            job : "Software Engineer",
15
            sayName : function () {
16
                alert(this.name);
17
            }
18
        };
19
        
20
        var friend = new Person();
21
        
22
        Person.prototype.sayHi = function(){
23
            alert("hi");
24
        };
25
        
26
        friend.sayHi();   //"hi" works!
27
28
29
        
30
    </script>
31
</head>
32
<body>
33
34
</body>
35
</html>