<script>
// 构造继承(call、apply继承)
function Animal(name){ // 3·这也要接收
this.name=name
this.say=function(){
console.log("我是say里面的方法"+ this.name);
}
}
Animal.prototype.eat=function(){
console.log("我是animal原型上的方法");
}
function Cat(name){ // 2·构造函数接收传来的参数
// Animal.apply(this, [name]) 参数是数组
Animal.call(this,name)
}
var tom=new Cat("aaa") // 1·实例传参,
console.log(tom.name);
// tom.say()
console.log(tom);
继承 call
最新推荐文章于 2021-07-27 23:23:23 发布