This is possible using a special code:
First define a namespace function and name the function of the object as follows:
var jaf = {};
function namedObject(strName) {
return {
name: strName,
toString: function() {
return this.name;
}
};
}
var namespace = function(strNs) {
var arrNsc = strNs.split(".");
var nsObj = null;
var i = 0;
var len = arrNsc.length;
var nsName = "";
if(arrNsc[0] === "jaf") {
nsObj = jaf;
i = 1;
nsName = "jaf.";
}
for(; i < len; i++) {
var ns = arrNsc[i];
nsName += (ns + ".");
if(!nsObj) {
if(!window[ns]) {
nsObj = window[ns] = namedObject(nsName.substring(0, nsName.length - 1));
}else {
nsObj = window[ns];
}
}else {
if(!nsObj[ns]) {
nsObj = nsObj[ns] = namedObject(nsName.substring(0, nsName.length - 1));
}else {
nsObj = nsObj[ns];
}
}
}
return nsObj;
}
Then you can do:
var ns = namespace("jaf.core.util");
ns.MyUtil = function() {
}
"jaf" , , . - :
var ns1 = namespace("abc.def.ghi")
ns1.get1() = function() {}
ns1.get2() = function() {}
ns1.get3() = function() {}
.