Skip to content

Instantly share code, notes, and snippets.

@AMekss
Created June 26, 2012 08:47
Show Gist options
  • Save AMekss/2994473 to your computer and use it in GitHub Desktop.
Save AMekss/2994473 to your computer and use it in GitHub Desktop.
Helper for global javascript namespace definition
// The MIT License (MIT) => http://www.opensource.org/licenses/mit-license
// Copyright (c) 2012 Artūrs Mekšs
//
// Runtime depndency jQuery 1.4 or above
(function($, rootspace){
window[rootspace] = function(namespace, object){
var setNamespace = function(namespace){
var root = window[rootspace];
$(namespace.split(".")).each(function(idx, name){
root = root[name] = root[name] || {};
});
return root;
};
return $.extend(true, setNamespace(namespace), object);
};
})(jQuery, "APP");
@duksis
Copy link

duksis commented Jun 26, 2012

fcuk php - the link works without it as-well http://www.opensource.org/licenses/mit-license ;)

@AMekss
Copy link
Author

AMekss commented Apr 11, 2016

Usage example:

APP("some.name.space", {
  init: function() {
    // function body
  }
);
// this would create name-spaced function available under:
APP.some.name.space.init();

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