jQueryの継承プラグイン

確かに、jQueryを使用する多くの開発者は、OOPを使用する大規模プロジェクトで継承の問題に直面します。 私自身も最近、同様の問題に戸惑っていたため、この困難な作業を支援するjQueryのプラグインを作成することにしました。 いくつかのアイデアはBase2から借用しています。



使い方



$.inherit([ base ], methods , [ statical ])



* This source code was highlighted with Source Code Highlighter .






どこで:

「マジック」メソッドとプロパティ



さらに、いくつかの「マジック」メソッドがあります。





//

var A = $.inherit(

{

__constructor : function (property) {

this .property = property;

},

getProperty : function () {

return this .property;

},

getStaticProperty : function () {

return this .__self.getStaticProperty();

}

},

{

staticProperty : 'static property of A' ,

getStaticProperty : function () {

return this .staticProperty;

}

});



//

var B = $.inherit(

A,

{

getProperty : function () {

return this .__base() + ' in B' ;

}

},

{

staticProperty : 'static property of B' ,

});



var instance = new B( 'value' );

alert(instance.getProperty());

alert(instance.getStaticProperty());

alert(B.staticProperty);



* This source code was highlighted with Source Code Highlighter .




プラグイン自体はここからダウンロードできます



All Articles