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();}