Tuesday, 3 September 2013

Jquery name space functional process is not understandable

Jquery name space functional process is not understandable

I searching across the web about the jquery.namespace process. finally i
got a answer in the stack overflow with this example script..
jQuery.namespace = function() {
var a=arguments, o=null, i, j, d;
for (i=0; i<a.length; i=i+1) {
d=a[i].split(".");
o=window;
for (j=0; j<d.length; j=j+1) {
o[d[j]]=o[d[j]] || {};
o=o[d[j]];
console.log(o);
}
}
// console.log(o); //Object {}
return o;
};
// definition
jQuery.namespace( 'jQuery.debug' );
jQuery.debug.test1 = function()
{
alert( 'test1 function' );
};
jQuery.debug.test2 = function()
{
alert( 'test2 function' );
};
// usage
jQuery.debug.test1();
jQuery.debug.test2();
It has 2 parts, once is "Jquery.namespace" - function and another is
declaring new methods to name space. But i unable to understand what is
"Jquery.namespace" function exactly do here.. i tried to understand line
by line, but i couldn't get the process what the function do here..
Any one explain me about the function, about how that's works? or any
other easy method to make name spacing using jQuery..
Thanks in advance

No comments:

Post a Comment