Jquery extender - the fastest way to create custom plugin
Jquery extendable is fastest and simpliest way to create a jquery plugin.
https://github.com/igorzg/jquery-extendable
Example:
(function($){
/**
* Constructor
*/
function Test(options, selector){
this._settings = $.extend({
a : 'a',
b : 'b'
}, options);
this._selector = $(selector);
this._init();
}
/**
* Extend prototype
*/
Test.prototype = {
/**
* Initalize
*/
_init : function(){
},
/**
* Private
*/
_private : function(){
throw new Error('Not visible');
},
/**
* Public method
*/
pub : function( a, b, c){
return a + b + c;
}
}
$.fn.Test = $.extendable(Test);
}(jQuery));
Run example:
$(function(){
$('div.box').Test({
a: 'works',
b : 'works_also'
});
//call pub method
$('div.box').Test("pub", 1 ,2 ,3 );
//not accessible and will not throw an error
$('div.box').Test("_private");
});
Written by Igor Ivanovic
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Plugin
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#