📜 ⬆️ ⬇️

Inheritance jQuery plugin

Surely, many developers using jQuery are faced with large inheritance problems in large projects using OOP. Since I myself recently had to be puzzled by a similar problem, I decided to write a plugin for jQuery that helps in this difficult task. Some ideas are borrowed from Base2.

How to use


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

* This source code was highlighted with Source Code Highlighter .

Where:

"Magic" methods and properties


In addition, there are several "magic" methods:

Example


//
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 .
The plugin itself can be downloaded from here .

')

Source: https://habr.com/ru/post/57380/


All Articles