案例:JavaScript案例     状态:可编辑再运行    进入横版
x
var objB = new ClassB("red", "John");
 
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.call(this, sColor);
19
20
    this.name = sName;
21
    this.sayName = function () {
22
        alert(this.name);
23
    };
24
}

 运行结果 
 北美留学生论坛