- 注册时间
- 2013-7-24
- 最后登录
- 2014-3-20
- 阅读权限
- 20
- 积分
- 32
- 精华
- 0
- 帖子
- 6
|
base()方法的一个问题,不知道算不算bug.
代码:
function ClassA(){}
ClassA.prototype.qqqq=undefined;
function ClassB(){
base(this,ClassA);
}
var classB=new ClassB(10);
报错: Uncaught TypeError: Cannot set property 'super' of undefined
function base(d,b,a){
var p=null,o=d.constructor.prototype,h={};
if(d.constructor.name == "Object"){
console.warn( "When you use the extends. You must make a method like 'XX.prototype.xxx=function(){}'. but not 'XX.prototype={xxx:function(){}}'.");
}
for(p in o)h[p]=1;
for(p in b.prototype){
if(!h[p])o[p] = b.prototype[p];
o[p][SUPER] = b.prototype;//应该是说o[p] 为 undefined, 即o["qqqq"] 为 undefined 的原因
}
b.apply(d,a);
}
因为其他框架的代码的继承方式有这种情况
//----其他框架
function Class1(){
this.a=undefined;
}
function Class2(){}
Class2.prototype=new Class1();
//----其他框架
//自己的代码用base继承其他框架的Class2
function MyClass3(){
base(this,Class2);
}
var myClass3=new MyClass3();
|
|