Created
May 21, 2013 19:52
-
-
Save tarmann/5622703 to your computer and use it in GitHub Desktop.
JavaScript: Underscore Mixin for Namespacing
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
_.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