Logos said:
That's true of any part of javascript. I'm only really familiar with
IE 5&6 and FF 2& 3's engines, which are slow on typeof AFAIK. Which
engine(s) are you referring to?
Any, pretty much.
A quick test of the relative speeds of "x in o", "Boolean(o.x)" and
"typeof x.x != 'undefined'" would be:
---
var x = { x: 42, y : 42 };
var t0 = new Date();
for (var i = 0; i < 1000000; i++) {
var u = "x" in x;
}
var t1 = new Date();
for (var i = 0; i < 1000000; i++) {
var u = Boolean(x.x);
}
var t2 = new Date();
for (var i = 0; i < 1000000; i++) {
var u = (typeof x.x != "undefined");
}
var t3 = new Date();
var result = [t1-t0,t2-t1,t3-t2]
---
It shows the following:
FF 3.0.10: 391,1071,444
Chrome 2.0.180: 737,1023,663
Opera 9.64: 250,359,266
IE 7: 500,1000,564 (estimated)
Safari 4 beta: 161,219,277
I.e., almost exactly the same pattern for all browsers: using "in" is
faster than "typeof", which is (much) faster than checking the actual
value (the exception begin Chrome that is fastest on typeof).
Ummm...by definition, "top" is in fact the top level document.
They're synonymous.
No, it's the top level window.
You can most definitely access any variables
declared at the top level using top.
The top level frame's global variables, yes (unless prohibited by XSS
security).
I use this syntax when I have a code library that might be in an
iframe, or might be in the top level page.
If the library is in the iframe, then you won't access it like this.
If it's in the top level page, you can access it from the iframe.
/L