案例:JavaScript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<title>Example</title>
4
</head>
5
<body>
6
<script type="text/javascript">
7
function ClassA(sColor) {
8
    this.color = sColor;
9
    this.sayColor = function () {
10
        alert(this.color);
11
    };
12
}
13
14
function ClassB(sColor, sName) {
15
    this.newMethod = ClassA;
16
    this.newMethod(sColor);
17
    delete this.newMethod;
18
    
19
    this.name = sName;
20
    this.sayName = function () {
21
        alert(this.name);
22
    };    
23
}
24
25
var objA = new ClassA("blue");
26
var objB = new ClassB("red", "John");
27
objA.sayColor();
28
objB.sayColor();
29
objB.sayName();
30
31
</script>
32
 
33
</body>
34
</html>
35