Last active
February 25, 2018 10:35
-
-
Save nefarioustim/f2db52672ca0ef7f6816d2abcc96ca44 to your computer and use it in GitHub Desktop.
JavaScript namespace helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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