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: <script ... prototype.js...> <script ... myscript.js...> 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) { } -- Rick Olson http://techno-weenie.net
2006/6/20, Rick Olson <technoweenie@gmail.com>:> > 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 } On 6/20/06, Yannick Koehler <yannick@koehler.name> wrote:> > 2006/6/20, Rick Olson <technoweenie@gmail.com>: > > > 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060620/b19636c4/attachment.html
2006/6/20, Jeff Avallone <jeff.avallone@gmail.com>:> 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