Last active
December 17, 2015 14:39
-
-
Save tarmann/5626210 to your computer and use it in GitHub Desktop.
JavaScript: Underscore Mixin Namespace
This file contains 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
/* | |
* Usage: _.namespace('App.Namespace.Here'); | |
* | |
*/ | |
_.mixin({ | |
namespace: function (path) { | |
var objects = path.split('.'), | |
namespace = window; | |
_.each(objects, function(obj, i){ | |
namespace[obj] = namespace[obj] || {}; | |
namespace = namespace[obj] | |
}); | |
return namespace; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment