function A(){ // just like component
alert('A constructor');
this.initComponent();
}
A.prototype = {
constructor : A,
initComponent : function() {
alert('a initComponent');
}
}
// var a = new A();
B = Ext.extend(A, { // just like window
initComponent : function() {
alert('b initcomponent');
B.superclass.initComponent.call(this);
}
});
b = new B();
B是A的子类了,new B()的时候为什么A函数会被调用到了。在java里面子类的构造函数里面调用super()倒是一个默认规定。
但是javascript,感觉肯定有个地方显示调用了,但是我找了很久没找到。
如果能指出是在Ext.extend的哪行源码最好了。
谢谢。
http://dragonshrimp.blog.163.com/blog/static/6904004920082281413980/
这上面有Ext.extend的用法和代码解读,里面有谈到“定义一个subFn函数,这个函数中会调用superFn函数”。不知道是否是你想要的答案,不过上面解读得挺透的,希望也能找到你想要的答案吧~~
下面这行:
B.superclass.initComponent.call(this);