<html> <head> <title>Example</title> </head> <body> <script type="text/javascript"> function ClassA(sColor) { this.color = sColor; this.sayColor = function () { alert(this.color); }; } function ClassB(sColor, sName) { //this.newMethod = ClassA; //this.newMethod(color); //delete this.newMethod; ClassA.apply(this, arguments); this.name = sName; this.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>
结果:
编辑上面的代码,点击查看结果。
yige.org
- 试一个