Convert String to legal namespaces - Node.js String

Node.js examples for String:Convert

Description

Convert String to legal namespaces

Demo Code


String.prototype.namespace = function(separator) {
    var ns = this.split(separator || '.'), p = window, i;
    for (i = 0; i < ns.length; i++) {
    p = p[ns[i]] = p[ns[i]] || {};/*from  w w w  .j  a va 2s.c o m*/
    }
};

//define legal namespaces here:
'localground'.namespace();
'localground.map'.namespace();
'localground.map.tiles'.namespace();

Related Tutorials