J
Jeff
I have a question about closures. Take for example the addBehavior
method below from the Low Pro library
Event.addBehavior = function(rules) {
var ab = this.addBehavior;
Object.extend(ab.rules, rules);
if (!ab.responderApplied) {
Ajax.Responders.register({
onComplete : function() {
if (Event.addBehavior.reassignAfterAjax)
setTimeout(function() { ab.reload() }, 10);
}
});
ab.responderApplied = true;
}
if (ab.autoTrigger) {
this.onReady(ab.load.bind(ab, rules));
}
};
var ab is initialized to this.addBehavior. It is then extended using
Object.extend(ab.rules.rules). However, in the Ajax.Responders
onComplete function, addBehavior is referenced using
Event.addBehavior.reassignAfterAjax instead of ab.reassignAfterAjax.
Then, immediately after, ab.reload is referenced. Why is this? Instead
of ab.rules, why wasn't
Object.extend(Event.addBehavior.rules, rules), or even
Object.extend(this.addBehavior.rules, rules)? Does it have to do with
closures?
method below from the Low Pro library
Event.addBehavior = function(rules) {
var ab = this.addBehavior;
Object.extend(ab.rules, rules);
if (!ab.responderApplied) {
Ajax.Responders.register({
onComplete : function() {
if (Event.addBehavior.reassignAfterAjax)
setTimeout(function() { ab.reload() }, 10);
}
});
ab.responderApplied = true;
}
if (ab.autoTrigger) {
this.onReady(ab.load.bind(ab, rules));
}
};
var ab is initialized to this.addBehavior. It is then extended using
Object.extend(ab.rules.rules). However, in the Ajax.Responders
onComplete function, addBehavior is referenced using
Event.addBehavior.reassignAfterAjax instead of ab.reassignAfterAjax.
Then, immediately after, ab.reload is referenced. Why is this? Instead
of ab.rules, why wasn't
Object.extend(Event.addBehavior.rules, rules), or even
Object.extend(this.addBehavior.rules, rules)? Does it have to do with
closures?