案例: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(color);
17
    //delete this.newMethod;
18
    ClassA.apply(this, arguments);
19
20
    this.name = sName;
21
    this.sayName = function () {
22
        alert(this.name);
23
    };
24
}
25
26
var objA = new ClassA("blue");
27
var objB = new ClassB("red", "John");
28
objA.sayColor();
29
objB.sayColor();
30
objB.sayName();
31
32
</script>
33
 
34
</body>
35
</html>
36