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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#