Prototype $A not defined

Hello,

I apologize for posting prototype related email to this list, yet I
have not seen any reference to email or list on the prototype web site
and I know the author of that library is part of the rails development
team so I am trying to reach him.

Basically I have installed “FireBug” which is a
javascript/html/css/dom debugger for firefox and since I plugged
prototype.js and added a call to Ajax.PeriodicalUpdater() inside my
scripts I often get 3 errors in FireBug.

They also show up in firefox javascript console, so I know it is not
related to firebug. The error is “$A not defined”. And the line is
prototype.js:48.

My web page include the script like this:

Therefore I would expect that by the time firefox handle myscript.js that prototype is fully loaded. Yet because the error seems to occurs only sometime, and that in normal situation I do not have any error detected. I think there is a problem about synchronisation between .js files. Is there a system in place to allow a script such as myscript.js to check for the state of loading of prototype.js to remove such race? Or maybe I am totally mislead by all this and there is an even more rationnal explanation to all this? -- Yannick Koehler

Is there a system in place to allow a script such as myscript.js to
check for the state of loading of prototype.js to remove such race?

if($A) {

}

2006/6/20, Rick O. [email protected]:

Is there a system in place to allow a script such as myscript.js to
check for the state of loading of prototype.js to remove such race?

if($A) {

}

Maybe I don’t get it but if I do this, the javascript will not
complain about $A not being defined as it attempt to resolve it’s
value to see if it is true or false?


Yannick Koehler

Yes, Javascript will complain about that. The better way to check if a
variable is defined or not is to do:

if (typeof $A != “undefined”) {
// Do stuff with $A
}

2006/6/20, Jeff A. [email protected]:

Yes, Javascript will complain about that. The better way to check if a
variable is defined or not is to do:

if (typeof $A != “undefined”) {
// Do stuff with $A
}

Ok make more sense…

But, does anyone knows why this is happening at all? I mean how can
firefox run my second script before my first script has been loaded
and executed?

The use of the Ajax.PerdiodicalUpdater was on the window.onload
therefore the document should have been loaded completely … so
while I now have what I think is a valid work-around, I’d like to have
a good understanding of the issue, if someone can provide it …


Yannick Koehler

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs