I check to see if NS.ajax exists. If so I do not need to redefine it. If it does not exist I redefine it.
I want to verify that this does what I think it does and I don't waste time interpreting the function below if I already have NS.ajax defined.
NS.ajax is the same as the anonymous function seen below.
Can someone verify?
/*ajax ** ** ** */ $P.ajax = (function () { if (NS.ajax) { return NS.ajax; } return function (config) { var xhr; if (config.type === 'get') { xhr = new window.XMLHttpRequest(); xhr.open('GET', config.url, true); xhr.onreadystatechange = function () { if (this.readyState === 4) { if (this.status === 200) { config.callback(xhr.responseText); } else { return false; } } }; xhr.send(null); return; } }; }());
$P.ajaxto a function. IfNS.ajaxexist that will be returned, otherwise an anonymous function will be.