orbited.js + stomp.js is breaking IE7 and IE8 array/objects for iterations

56 views
Skip to first unread message

mark

unread,
Jan 20, 2009, 11:44:20 PM1/20/09
to orbite...@googlegroups.com
after adding Orbited.js and stomp.js, all my iterations using for
statement on array and objects are broken in IE7 and IE8

for ex:
for (idx in my_array) {
do_stuff(my_array[idx]);
};
is not working anymore.


I took a screen-shot from my debugger:
http://bayimg.com/fAnhaAaBb

a screenshot without Orbited.js and stomp.js is below
http://bayimg.com/FaNhEAabb

for the first element of the array, instead of the value, i get some
weird text/function -indexof.

has anyone had this problem? how to fix this?
thanks a lot!

Jacob Rus

unread,
Jan 21, 2009, 1:14:20 AM1/21/09
to orbite...@googlegroups.com
Mark wrote:

> for (idx in my_array) {
> do_stuff(my_array[idx]);
> };
>
> is not working anymore.

That's a very fragile operation in JavaScript, and writing code like
that is not recommended. Instead just iterate using:

for (var i = my_array.length - 1; i >= 0; i--){
my_array[i]
};

or something similar.

That said, Orbited probably shouldn't break it either. Neither of
your screenshots load for me, so I'm not sure what the problem was,
exactly. I assume either Orbited.js or stomp.js adds something to the
array prototype? Can you figure out where the addition happens, and
what it's there for?

Cheers,
Jacob

Michael Carter

unread,
Jan 21, 2009, 1:21:50 AM1/21/09
to orbite...@googlegroups.com

As far as I know, we don't add anything to any prototypes, and in fact that has always been one of our goals.. Its possible that something managed to sneak in there over the last few sub-versions, its probably worth checking out.

-Michael Carter

mark

unread,
Jan 21, 2009, 2:12:33 AM1/21/09
to orbite...@googlegroups.com, jaco...@gmail.com, carter...@gmail.com
On Tue, Jan 20, 2009 at 5:14 PM, Jacob Rus <jaco...@gmail.com> wrote:
> Mark wrote:
>
> > for (idx in my_array) {
> > do_stuff(my_array[idx]);
> > };
> >
> > is not working anymore.
>
> That's a very fragile operation in JavaScript, and writing code like
> that is not recommended. Instead just iterate using:
>
> for (var i = my_array.length - 1; i >= 0; i--){
> my_array[i]
> };
right now as a work around im using jquery's $.each, and it seems to be working.


> That said, Orbited probably shouldn't break it either. Neither of
> your screenshots load for me, so I'm not sure what the problem was,

i have attached the two images. let me know if you still have problems
with them.


> exactly. I assume either Orbited.js or stomp.js adds something to the
> array prototype? Can you figure out where the addition happens, and

i am completely new to javascript and orbited. if you can give me some pointers
on how to do it, i can definitely try.

ie-with-index-of.png
ie-without-index-off.png

Mario Balibrera

unread,
Jan 22, 2009, 10:46:57 AM1/22/09
to orbite...@googlegroups.com
The problem was in js.io, and has been corrected in the js.io trunk. The offending lines aren't actually necessary in the current code, so if you want you can fix the problem by removing the following from near the top of stomp.js:

// Implement Array.indexOf (needed in IE 7 or lower).
// NB: This was borrowed from Mozilla.
// See http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:indexOf
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(elt /*, from*/) {
var len = this.length;
var from = Number(arguments[1]) || 0;
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
if (from < 0)
from += len;

for (; from < len; from++) {
if (from in this && this[from] === elt)
return from;
}
return -1;
};
}
There you go.

Mario Balibrera

mark

unread,
Jan 22, 2009, 1:08:36 PM1/22/09
to orbite...@googlegroups.com
thanks a lot!!!
can you fix this in the svn version also?

Mario Balibrera

unread,
Jan 22, 2009, 2:25:02 PM1/22/09
to orbite...@googlegroups.com
Done. ;)

Mario Balibrera
Reply all
Reply to author
Forward
0 new messages