//简单的对象冒充
function Father(name){
this.name=name;
this.method= function(){
alert("father method!")
}
}
function Son(name){
this.fatherTemp = Father;
this.fatherTemp(name);
delete this.fatherTemp;
}
var son = new Son("son");
alert(son.name);
son.method();
2.call对象冒充
//使用call、apply方法的对象冒充
function Father(name){
this.name=name;
this.method=function(){
alert("father method!")
}
}
function Son(name){
Father.call(this,name);
}
var son = new Son("son")
alert(son.name);
son.method();
二、原子性的对象冒充
function Father(name){
this.name=name;
this.method=function(){
alert("father method!")
}
}
function Son(){
}
Son.prototype = new Father("father");
var son = new Son();
alert(son.name);
son.method();
三、对象继承的常用方式
function Father(name){
this.name=name;
}
Father.prototype.method=function(){
alert("father method!")
}
function Son(name){
Father.call(this,name)
}
Son.prototype = new Father();
Son.prototype.show=function(){
alert("show")
}
var son = new Son();
alert(son.name)
son.method();
son.show();