Skip Menu |

This queue is for tickets about the HTML-Ajax CPAN distribution.

Report information
The Basics
Id: 12213
Status: resolved
Priority: 0/
Queue: HTML-Ajax

People
Owner: Nobody in particular
Requestors: adamk [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.01
Fixed in: (no value)



Subject: Functions polluting the window more far too much
If you want to grow this module, we're going to need to get it a bit more self-contained. Functions like 'callAjaxGet' should just be defined in the class, not also on the root window. You do this using a prototype definition. It's what separates "real" JavaScript classes from assembled ones (like the current version). You want something like this Ajax.prototype = { version : 0.01, isAsync : false, agent : null, lastException : '', get : function (url, callback, headers) { return this.open('GET', url, null, callback, headers); }, open : ..., etc : ..., etc : ... } // The constructor keeps the agent logic as normal function Ajax () { if ( typeof XMLHttpRequest != 'undefined' ) { this.agent = new XMLHttpRequest(); } if ( this.agent == null ) { var axos = [ 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ]; for ( var i = 0; this.agent == null && i < axos.length; i++ ) { try { this.agent = new ActiveXObject(axos[i]); } catch(e) { this.lastException = e; this.agent = null; } } } }