寄生组合式继承
2017-03-26 00:47
337 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> </body> <script type="text/javascript"> function Super(name) { this.name=name; this.color="red"; } Super.prototype.sayName=function () { alert(this.name); } function sub(name,age) { Super.call(this,name) this.age=age; } sub.prototype=new Super(); sub.prototype.constructor=sub; sub.prototype.sayAge=function () { alert(this.age) } var supTest=new Super("chengkai")//父函数的属性不受影响。 var subTest=new sub("kai",23);//子函数也可以调用父函数的函数,同时传递自己定义的属性。 //sub.prototype.sayAge(); //sub.prototype.sayName(); subTest.sayAge(); subTest.sayName(); supTest.sayName(); alert(supTest.color); </script> </html>
相关文章推荐
- JavaScript-------寄生组合式继承
- js继承6-----寄生组合式继承
- 寄生组合式继承
- 设计模式知识连载(10)---继承_6:终极继承者-寄生组合式继承
- JavaScript 继承---寄生组合式继承
- JavaScript继承基础讲解,原型链、借用构造函数、混合模式、原型式继承、寄生式继承、寄生组合式继承
- JavaScript寄生组合式继承实例详解
- 组合继承 和 原型式继承、寄生组合式继承
- javascript 的 继承(六) 之 寄生组合式继承
- [js高手之路]寄生组合式继承的优势详解
- JavaScript继承基础讲解(原型链、借用构造函数、混合模式、原型式继承、寄生式继承、寄生组合式继承)
- JavaScript高级程序设计之寄生组合式继承
- [javascript]寄生组合式继承
- 【JavaScript】6.3.6寄生组合式继承
- js寄生组合式继承
- JavaScript高级程序设计之面向对象的程序设计之继承之寄生组合式继承第6.3.6讲笔记
- javaScript设计模式之面向对象编程(object-oriented programming,OOP)--寄生组合式继承
- Javascript继承6:终极继承者----寄生组合式继承
- 【JavaScript学习】面向对象的程序设计(7):寄生式继承和寄生组合式继承
- JavaScript中的寄生组合式继承方式