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