Skip to content

Instantly share code, notes, and snippets.

@adamjmcintyre
Created May 11, 2012 14:47
Show Gist options
  • Save adamjmcintyre/2660219 to your computer and use it in GitHub Desktop.
Save adamjmcintyre/2660219 to your computer and use it in GitHub Desktop.
Boilerplate for creating namespaced modules in js strict mode
;(function(win, $){
"use strict";
// Check to see if our global is available as a member of window; if it is, our namespace root exists; if not, we'll create it.
var foospace = win.foospace = (typeof win.foospace !== "undefined") ? win.foospace : {};
(foospace.module = function(){
return{
_init : function(){
// Etc. etc.
}
}
}())._init();
}(window, jQuery));
@nickcooley
Copy link

Is the intent here to pass along a namespace or just to check if one type of namespace is there?

You could certainly enhance by using this approach to check for any particular namespace, thus creating if unavailable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment