function Parent(name)
{
this.name = name;
this.sayHello = function()
{
alert(this.name)
}
}
function Child(name, age)
{
//用子类的this去冒充父类的this,实现继承
this.method = Parent;
this.method(name);
delete this.method;
//此后的this均指子类
this.age = age;
this.sayWorld = function()
{
alert(age);
}
}
var parent = new Parent("张三");
var child = new Child("李四", 20);
例子中为什么要把Parent赋给Child的临时属性this.method再运行,直接不赋给this.method,直接运行method(name)不行吗?求教
直接运行还叫继承吗? 那就是调用啊