W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<html> <head> <title>Example</title> </head> <body> <script type="text/javascript"> function ClassA(sColor) { this.color = sColor; } ClassA.prototype.sayColor = function () { alert(this.color); }; function ClassB(sColor, sName) { ClassA.call(this, sColor); this.name = sName; } ClassB.prototype = new ClassA(); ClassB.prototype.sayName = function () { alert(this.name); }; var objA = new ClassA("blue"); var objB = new ClassB("red", "John"); objA.sayColor(); objB.sayColor(); objB.sayName(); </script> </body> </html>