Skip to content

Instantly share code, notes, and snippets.

// Simplified one-liner version with a bit of added functionality
String.prototype.namespace = function(objects, scope, separator){
return Object.extend(this.split(separator || '.').inject((scope || window), function(parent, child){
return (parent[child] = parent[child] || {});
}), objects || {});
}
// Sample usage
'com.pixeldepo.some.package'.namespace();
'com.pixeldepo.some.other.package'.namespace();