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();
}
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();
}
相关文章推荐
- JS实现继承的几种方式详述(推荐)
- js实现继承
- js继承的4种方法
- js真正的原型继承
- js继承
- 用Ext实现js方法的继承,以及扩展Ext组件的开发
- 【cocos2d-x从c++到js】04:cocos2d-x for js中的继承 推荐
- js实现继承
- js之原型链与继承
- js的三种继承方式及其优缺点
- js 继承和原型链
- js继承的三种方式
- javascript中的继承(JS基于原型链的继承),以及JS中的call和apply函数
- js中的prototype和基于prototype的继承总结
- js继承
- js继承
- javascript(js)创建对象的模式与继承的几种方式
- js继承
- JS实现继承的几种方式