Skip to content

Instantly share code, notes, and snippets.

@tarmann
Last active December 17, 2015 14:39
Show Gist options
  • Save tarmann/5626210 to your computer and use it in GitHub Desktop.
Save tarmann/5626210 to your computer and use it in GitHub Desktop.
JavaScript: Underscore Mixin Namespace
/*
* 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