@ref prototype.js
I have seen this Prototype.js ajax syntax used everywhere. However I have not been able to figure out what role ajaxCall plays here. It holds NO reference to the Ajax object being created. Prototype, by default creates an instance for every new Ajax.Request you call, so why are people using the variable assignment at all when it serves no purpose, (that I can see)?
var ajaxCall = new Ajax.Request(filepath, {
onSuccess: this.requestSuccess.bind(this)
});
myObject.prototype.requestSuccess = function() {
log: resp.status; //yea
log: ajaxCall.status; //nea
}
JSLint is saying “You’re creating some objects but immediately discarding them; the only possible reason you can be doing that is that the act of creating the objects has side-effects, which is weird.”.
Constructors should not have side-effects other than constructing the object. That’s at least my opinion. PrototypeJS folks seem to think differently though.