Created
April 15, 2012 00:34
-
-
Save karloscarweber/2389040 to your computer and use it in GitHub Desktop.
A Jquery Function Extention boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Jquery Function BoilerPlate for newbies | |
// | |
// | |
// Surrounded by parentheses to allow anonymous founcitons on the inside | |
(function($){ // pass the jquery pseudo variable "$" into the function in order to create it's awesomeness. | |
$.fn.yourFucntion = function(userConfig) { | |
// please note, the "this" variable in the current scope will refer to the | |
// element or object that this function is called upon. | |
// Set up a default Configuration | |
var config = { | |
varOne : 1, | |
varTwo : 2, | |
varThree 3 | |
}; | |
// if user configuration is supplied then save that into config | |
// note: this uses jquery's extend function. | |
if (userConfig) $.extend(true, config, userConfig); | |
// you must return the current object to allow jquery method chaining. | |
return this; | |
}; // End of new function Declaration | |
// End of a Closure I think. | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment