Closed GoogleCodeExporter closed 8 years ago
what does the typeof operator return?
Original comment by simon.po...@gmail.com
on 30 Mar 2012 at 10:03
the typeof operator is a bit useless, since it only works well for primitive
types. "typeof []" just returns "Object". In
http://tobyho.com/2011/01/28/checking-types-in-javascript/ there is a more
detailed explanation.
Original comment by luiz.mi...@gmail.com
on 30 Mar 2012 at 10:26
oh yes of course. ha. that's why i have the test i have. i can't really see off
the top of my head why that test would fail when running in an iframe. iframes
need arrays too, right?
Original comment by simon.po...@gmail.com
on 30 Mar 2012 at 10:41
yep, the problem occurs when you create an array inside an iframe, and transfer
it to the main window. By some unknown reason, the Array object looses his
prototype, and consequently the 'constructor' attribute becames undefined. You
can see that behaviour debugging the example with firebug.
Original comment by luiz.mi...@gmail.com
on 30 Mar 2012 at 10:48
hmm, i see.
that array test you pasted is really not a thing of beauty. let me have a think
about my options.
Original comment by simon.po...@gmail.com
on 30 Mar 2012 at 10:52
[deleted comment]
ok, sure. Anyway, if there is no better option, you can move the test to a
function, so you can use it like '_isArray(obj)'
Original comment by luiz.mi...@gmail.com
on 30 Mar 2012 at 11:35
Yeah we could do that. Or perhaps defer to jquery or mootools or YUI. I wonder
what they all use for this test.
Original comment by simon.po...@gmail.com
on 31 Mar 2012 at 12:29
i was on my phone before...just had a chance to look at the link you sent.
this bit is key isn't it:
"Above, we created a variable arr inside the context of the iframe and set it
to the array [1, 2, 3]. However, we get false when we ask whether it is a
instance of Array. What is happening?!! Behold.
Array === iWindow.Array // false
The Array in the iframe is not the same Array as our Array! This is true for
all built-in objects: there are two versions of all of them! Basically, we have
parallel universes! OMG!
What this means is that an array created within the iframe is only an instance
of the Array constructor within the iframe"
weird, but then Javascript is nothing if not a little quirky. i guess i will
just change all my tests to use that. damn its ugly though.
Original comment by simon.po...@gmail.com
on 31 Mar 2012 at 6:02
this has been done in 1.3.8. i also added a string test, since there are a
couple of those in the code, and i presume they would have the same behaviour.
Original comment by simon.po...@gmail.com
on 31 Mar 2012 at 6:20
1.3.8 was released today.
Original comment by simon.po...@gmail.com
on 1 Apr 2012 at 7:53
Original issue reported on code.google.com by
luiz.mi...@gmail.com
on 30 Mar 2012 at 5:28Attachments: