Problem Description: When applying Events to elements or window, Firefox throws up an error if page is still loading:
Error: $A is not defined
Source File: prototype.js Line: 79
I've been looking all over the Internet to find a solution, but it appears this bug was in prototype for a while and I could not find a fix for a long time.
After all, I've decided to look into code myself. First I moved declaration of $A function in front of the code - no luck.
Finally, after some thinking, I applied a patch, that WILL NOT ALLOW executing $A function if it's not initialized.
And it worked just fine !!! Although, I can't explain the origin of this problem, had no time to dig further.
Just grab the code and forget this problem ever existed :)
Function.prototype.bindAsEventListener = function(object) {
var __method = this, args = $A(arguments), object = args.shift();
return function(event) {
if(typeof $A === 'function'){ // <-- Added Firefox Fix
return __method.apply(object, [( event || window.event)].concat(args).concat($A(arguments)));
}
}
}
// "Thanks to Dave for the hint!"
Function.prototype.bind = function() {
var __method = this, args = $A(arguments), object = args.shift();
return function() {
if(typeof $A === 'function'){ // <-- Added Firefox Fix
return __method.apply(object, args.concat($A(arguments)));
}
}
}
bind: function() {
if (arguments.length < 2 && arguments[0] === undefined) return this;
var __method = this, args = $A(arguments), object = args.shift();
return function() {
if(typeof $A === 'function'){ // <-- Added Firefox Fix
return __method.apply(object, args.concat($A(arguments)));
}
}
},
bindAsEventListener: function() {
var __method = this, args = $A(arguments), object = args.shift();
return function(event) {
if(typeof $A === 'function'){ // <-- Added Firefox Fix
return __method.apply(object, [event || window.event].concat(args));
}
}
},
Comments