首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript学习之对象承继

2012-08-16 
javascript学习之对象继承1.对象冒充方法function classA() {this.color xxx}function classB() {this.

javascript学习之对象继承

1.对象冒充方法

function classA() {

this.color = xxx;

}

function classB() {

this.father = classA;

this.father();

delete this.father;

.............

}

将classA看做是一个正常的函数赋值给classB的father,之后删除新方法的代码定义

ps:双继承

function classC{

this.father = classA;

this.father();

delete this.father;

this.father = classB;

this.father();

delete this.father;

}

2.call方法

每个方法都有自己的call函数,call函数将第一个参数当做this,之后的参数依次当做参数

function classA(aa) {

this.color = aa;

}

function classB(aa) {

classA.call(this , aa)

.............

}


1楼lmdcszh3天前 16:29
交流学习:http://blog.csdn.net/lmdcszh/article/details/7751439n要是有些实例就更好了

热点排行