Skip to content

Instantly share code, notes, and snippets.

@Kilian
Created October 11, 2009 17:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kilian/207764 to your computer and use it in GitHub Desktop.
Save Kilian/207764 to your computer and use it in GitHub Desktop.
//place inside an anonymous function
(function ($) {
// on document ready code
$(function(){
$.namespace.functionName();
$.namespace2.anotherFunctionName();
});
}(jQuery));
/* a small pattern to make jQuery functionality maintainable and readable*/
//place inside an anonymous function
(function ($) {
//request namespace or make a new object
$.namespace = $.namespace || {};
//add (new) functions to your namespace
$.extend($.namespace, {
functionName: function() {
//your code...
},
anotherFunctionName: function() {
//your code...
},
});
}(jQuery));
//place inside an anonymous function
(function ($) {
//request namespace or make a new object
$.namespace2 = $.namespace2 || {};
//add (new) functions to your namespace
$.extend($.namespace2, {
functionName: function() {
//your code...
},
anotherFunctionName: function() {
//your code...
},
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment