[Proto-Scripty] Re: array.indexOf fails sometimes in IE8
Hi, You're probably running into equality vs. identity (loose equality vs. strict equality). The emerging standard for what Array#indexOf is supposed to do uses strict equality (===), not ==, whereas previously Prototype used loose equality. This is an issue with strings because mpg !== new String(mpg) even though mpg == new String(mpg) Oddly, I can't replicate the behavior you're seeing on IE8 if I have Prototype loaded, but I can easily do so without it by calling isVideoFile(new String(mpg)). HTH, -- T.J. Crowder tj / crowder software / com www.crowdersoftware.com On Sep 1, 11:14 pm, Mojito tokyot...@gmail.com wrote: My function works as expected in all non-IE browsers. But when I try it in IE8, it doesn't scan the array correctly. Any easy workaround rather than implementing my own indexOf()? + function isVideoFile(extension) { extension = extension.strip(); alert(typeof extension); alert(extension); alert(['3g2', '3gp', 'asf', 'asx', 'avi', 'flv', 'mkv', 'mov', 'mp4', 'mpg', 'mpeg', 'qt', 'rm', 'vob', 'wmv'].indexOf (extension)); } + The output when I pass in 'mpg': 1) string 2) mpg 3) -1 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: array.indexOf fails sometimes in IE8
I (Mojito) [don't know why my first post name differs from reply name] have solved by issue. I was passing in strings with '\0' on their ends. So 'mpg\0' does not equal 'mpg'. It was a nightmare to debug because '\0' is invisible. On Sep 2, 10:29 am, enigment enigm...@gmail.com wrote: Ah, that's the missing piece, the difference between a string primitive and a string object. Got it. e On Sep 2, 12:17 pm, T.J. Crowder t...@crowdersoftware.com wrote: There's a difference between primitives (mpg) and objects (new String (mpg)). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: array.indexOf fails sometimes in IE8
On Sep 3, 1:56 am, enigment enigm...@gmail.com wrote: Hmmm, even outside the indexOf() question, this is a bit creepy to me. I hadn't previously tested, but these are all true, at least in Firefox 3.5 and IE8: [...] new String(mpg) !== new String(mpg) new String(mpg) != new String(mpg) Because that is comparing two different objects, which can never be equal. [...] new Number(1) != new Number(1) Same here. [] != [] new Array() != new Array() new Array() != [] new Object() != {} And again. Object literal syntax is identical to using the new operator, only faster. Is it an identity test -- is it the same actual object? -- maybe coupled with the way various types of data are stored internally? It looks like once the string mpg has been created, another literal msg is the same, but a new String object containing the same literal is not. The analogous tests with Number, Array, and Object values indicate somewhat different behavior, but since it's consistent across IE and Firefox, it seems inherent in the language. Can anyone explain, not *how* this actually works, but the logic behind it? That is how it is specified by the ECMA-262 specification, every object has a unique identity. -- Rob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---