ci sono vari metodi, il più semplice è un Wrapper tipo questo
codice:
function WAjax(url){
return new Ajax(url, {
update: $('update'),
onRequest: function() {
this.options.update.setHTML("Loading...");
},
onComplete: function(text) {
alert("Complete! " + text);
},
onFailure: function() {
alert("Non è stato possibile eseguire la richiesta correttamente");
}
});
};
WAjax('mypage_2.htm').request();
[edit]
per completare, un altor metodo è il self wrapping tramite extended prototype
codice:
Ajax = (function(Ajax){
function I(){};
I.prototype = Ajax.prototype;
function MyAjax(url, Object){
if(this instanceof MyAjax)
Ajax.call(this, url, Object);
else
return new MyAjax(url, Object);
};
MyAjax.prototype = new I;
MyAjax.prototype.constructor = Ajax;
return MyAjax;
})(Ajax);
var ajax = new Ajax(url, {obj:ect});
ajax.request();
// oppure, tramite factory design pattern implicito
Ajax(url, {obj:ect}).request();
Io avrei usato questo, ma è un pelino più arduo da comprendere (se interessa, link in sign circa JavaScript prototypal inheritance, c'è questo ed altro ancora)