Skip to content

Instantly share code, notes, and snippets.

@jakemcgraw
Created March 10, 2010 20:17
Show Gist options
  • Save jakemcgraw/328318 to your computer and use it in GitHub Desktop.
Save jakemcgraw/328318 to your computer and use it in GitHub Desktop.
Organize jQuery code
var tspot = jQuery.extend(true, window.tspot || {}, {
log : function(message) {
(window.console && window.console.log) ?
window.console.log(message) :
alert(message);
},
// page specific functions under their own ns
});
jQuery(function($){
// (1) Do something
tspot.log("Done with (1)");
// (2) Do something else
tspot.log("Done with (3)");
// (3) Do something else...
tspot.log("Done with (3)");
});
// Evented approach
jQuery(function($){
$(document)
.bind("tspot.action1", function(e, p1, p2){
tspot.log("I performed action1");
})
.bind("tspot.action2", function(e, p1){
tspot.log("I performed action2");
});
$(document).trigger("tspot.action1").trigger("tspot.action2");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment