您的位置:首页 > Web前端 > JavaScript

JS 中的继承

2008-11-04 11:08 309 查看
主要有三种方法: 1. this.method=Parent; this.method=Parent's constructor 2. Parent.call(this,arg,arg,arg.....);3.Parent.apply(this,arg.arg...) //for Array 还是来点实际的吧...

function P(name){

this.name=name;

this.p1=function(){

alert('Parent Constructor');

}

return this;

}

function C(name,id){

//this.method=P;

//this.method(name); //1st method

//P.call(this,name); //2nd method

P.apply(this,new Array(name));//3rd method

this.id=id;

this.dis=function(){

alert(this.name);

}

}

function dis(){

alert(this.name);

}

function t(){

var cc=new C('N','Id');

cc.dis();

cc.p1();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: