jQuery类继承 [英] jquery class inheritance
本文介绍了jQuery类继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var A=function(){
};
$.extend(A.prototype, {
init:function(){
alert('A init');
}
});
var B=function(){
};
$.extend(B.prototype,A.prototype,{
init:function(){
alert('B init');
}
});
var p=new A();
p.init();
var x=new B();
x.init();
以上是在jQuery中创建类和继承的最佳方法吗?在B的init中,如何调用父级的init(类似于OO语言中的super.init())?
is the above the best way to create class and inheritance in jQuery? In B's init how do I invoke parent's init (similar to super.init() in OO languages)?
推荐答案
对于OO,最好在jQuery之外查看. jQuery基于选择器返回的集合.
For OO, it's best to look outside jQuery. jQuery is based on collections returned by selectors.
如果您要上课,可以选择以下选项: Base2 , JS.Class .
If you want classes, some choices are Base2, Joose, and JS.Class.
这篇关于jQuery类继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文