标签:io java ar sp cti log on c new
<script> function Person(name, age) { this.name = name; this.age = age; this.family = ["father" , "mather" , "sister"] ; } Person.prototype = { constructor: Person, say : function () { return "name : " + this.name + " age: " + this.age; } } ; function Teacher(name ,age ){ Person.call(this , name ,age ) ; } Teacher.prototype = new Person() ; var t = new Teacher("wangmeili" , 18) ; console.log(t.say()) ;//name : wangmeili age: 18 </script>
组合继承= 对象冒充+ 原型继承
对象冒充只能继承构造函数中的构造,而原型链继承无法实现构造函数传参。两者结合,才能相得益彰。
标签:io java ar sp cti log on c new
原文地址:http://my.oschina.net/itfanr/blog/313421