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

js 对象冒充解决方法

2012-02-05 
js 对象冒充有没有无参构造函数的继承呢?类似JScript codefunction a(){this.showfunction(){alert(a)

js 对象冒充
有没有无参构造函数的继承呢?
类似

JScript code
function a(){    this.show=function(){        alert("a");    }}function b(){    this.myA=a;    delete this.myA;}function ok(){        var myB= new b();    myB.show();}

这段代码是我自己写的不知道为什么不能运行,求大师指点!

[解决办法]
function b(){
this.myA=a;
delete this.myA;
}
你都没将a中的属性拷贝到b中
this.myA();

其实这里是模拟了call的操作。。。我觉得直接用call会比较直观点

JScript code
function a(){    this.show=function(){        alert("a");    }}function b(){   a.call(this)}function ok(){        var myB= new b();    myB.show();} 

热点排行