# Prototype $A not defined

**URL:** <https://www.ruby-forum.com/t/prototype-a-not-defined/63944>\
**Category:** Rails\
**Created:** [June 20, 2006, 7:34pm UTC](https://www.ruby-forum.com/t/prototype-a-not-defined/63944 "2006-06-20T19:34:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yannick\_Koehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f9ae1b/32.png) [@Yannick\_Koehler](https://www.ruby-forum.com/u/Yannick_Koehler)\
**Post date:** [June 20, 2006, 7:34pm UTC](https://www.ruby-forum.com/t/prototype-a-not-defined/63944/1 "2006-06-20T19:34:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Yannick\_Koehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f9ae1b/32.png) [@Yannick\_Koehler](https://www.ruby-forum.com/u/Yannick_Koehler)\
**Post date:** [August 3, 2006, 2:24pm UTC](https://www.ruby-forum.com/t/prototype-a-not-defined/63944/2 "2006-08-03T14:24:06Z")

</div>

> 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) {

}

---

<div class="post-metadata">

**Author:** ![Yannick\_Koehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f9ae1b/32.png) [@Yannick\_Koehler](https://www.ruby-forum.com/u/Yannick_Koehler)\
**Post date:** [August 15, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/prototype-a-not-defined/63944/3 "2006-08-15T14:21:42Z")

</div>

2006/6/20, Rick O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > 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

---

<div class="post-metadata">

**Author:** ![Yannick\_Koehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f9ae1b/32.png) [@Yannick\_Koehler](https://www.ruby-forum.com/u/Yannick_Koehler)\
**Post date:** [August 15, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/prototype-a-not-defined/63944/4 "2006-08-15T14:21:42Z")

</div>

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  
}

---

<div class="post-metadata">

**Author:** ![Yannick\_Koehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f9ae1b/32.png) [@Yannick\_Koehler](https://www.ruby-forum.com/u/Yannick_Koehler)\
**Post date:** [August 15, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/prototype-a-not-defined/63944/5 "2006-08-15T14:21:42Z")

</div>

2006/6/20, Jeff A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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
