Skip to content

Instantly share code, notes, and snippets.

@nefarioustim
Last active February 25, 2018 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nefarioustim/f2db52672ca0ef7f6816d2abcc96ca44 to your computer and use it in GitHub Desktop.
Save nefarioustim/f2db52672ca0ef7f6816d2abcc96ca44 to your computer and use it in GitHub Desktop.
JavaScript namespace helper
/* jshint esnext: true */
(function (){
"use strict";
let NEF = window.NEF || {};
NEF.namespace = function() {
let ln = arguments.length, i, value, x, xln, parts, object;
for (i = 0; i < ln; i++) {
value = arguments[i];
parts = value.split(".");
object = window[parts[0]] = Object(window[parts[0]]);
for (x = 1, xln = parts.length; x < xln; x++) {
object = object[parts[x]] = Object(object[parts[x]]);
}
}
return object;
};
NEF.ns = NEF.namespace;
window.NEF = NEF;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment