Forum: Ruby on Rails Very strange javascript error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Charlie (Guest)
on 2006-05-11 17:01
Some strange javascript errors happen in the situation:
Browser commits a xmlhttprequest to rails server,which will response
some DOM data and javascript scriplets to add some operation to those
DOM data.
All the following script are the responseText from webrick.
Error 1):
<script>
function Circle(x, y, r)
{
    this.x = x;
    this.y = y;
    this.r = r;
}
new Circle(0,0,0);
</script>
The above code will through "Circle undefined" error under both
firefox1.5 and IE6
<script>
Circle=function(x, y, r)
{
    this.x = x;
    this.y = y;
    this.r = r;
}
new Circle(0,0,0);
</script>
This code will work normally,therefore,the following returned code will
also through "xx undefined" error
<select  onchange="refresh();">......</select>
<script>
function refresh(){}//will cause "refresh undefined" error
/*
refresh=function(){}//will work normally
*/
</script>

What a strange!


Error 2):
Considering the follwing three scriptlets as a responseText to ajax
request:
code one:
<script>
for (i=0;i<$('divId').options.length;i++){
  justforTest=0;
}
</script>

code two:
<script>
var len=$('divId').options.length
for (i=0;i<len;i++){
  justforTest=0;
}
</script>

code three:
<script>
len=$('divId').options.length
for (i=0;i<$('divId').options.length;i++){
  justforTest=0;
}
</script>

Of the three scriplets,only the last one will work normally,the former
two will cause Firefox1.5 to collapse! (All three codes will be normal
under IE)
Oooo~~~~~~

Anyone who can explain me for these errors?
This topic is locked and can not be replied to.