JS 继承实例分析
更新时间:2008年11月04日 12:21:19 作者:
主要有三种方法: 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();
}
相关文章
Javascript 面向对象(一)(共有方法,私有方法,特权方法)
最近在网上盾一些JS面向对象的东西。把其他高手们总结的东西,加上自己的理解,总结一下2012-05-05
javascript 单例模式演示代码 javascript面向对象编程
单例模式的好处就是:类只实例化一次,省资源,节省开销,提高速度,学习js面向对象编程的朋友可以参考下。2010-04-04


最新评论