Prev: html form in javascript variable
Next: Microsoft and attributes--will they ever figure them out?
From: David Mark on 15 Nov 2009 00:23 On Nov 15, 12:20 am, "Richard Cornford" <Rich...(a)litotes.demon.co.uk> wrote: > David Mark wrote: > > On Nov 14, 11:55 pm, Richard Cornford wrote: > >> Richard Cornford wrote: > >>> ... After all, you can show them the environments where > >>> objects result in 'undefined'... > > >> That 'undefined' should have been 'unknown', but you probably > >> figured that out already. > > > Actually, I thought you meant document.all in FF quirks mode. ;) > > Fair enough, that will do as your third example of a host object - > typeof - oddity that can be stated. (Which reminds me, there is (or was, > as it has been criticised) something in Safari that claims to be > 'undefined' even though it can be shown to exist (be an object or > function). I don't recall the detail, but I think Garrett may be in a > position to say what it is (without looking it up in the ES 4/3.1 > mailing list archives.)) > The - item - method of DOM collections I think. So yeah, in reported history, there are a handful of host object typeof anomalies and all but one - unknown - are native type names. Not one "array" in the bunch.
From: David Mark on 15 Nov 2009 00:56 On Nov 14, 11:36 pm, "Richard Cornford" <Rich...(a)litotes.demon.co.uk> wrote: [...] > > Yes, it is precisely that sort of thing that places arbitrary > constraints on the set of supported browsers without there being any > real need to be doing so. > And I think it goes without saying that such arbitrary constraints are confining even on the desktop. But for scripts with mobile aspirations (one of the reasons dynamic script loading is being considered) it seems like the worst possible choice.
From: Garrett Smith on 15 Nov 2009 01:35 Richard Cornford wrote: > David Mark wrote: >> On Nov 14, 11:55 pm, Richard Cornford wrote: >>> Richard Cornford wrote: >>>> ... After all, you can show them the environments where >>>> objects result in 'undefined'... >>> >>> That 'undefined' should have been 'unknown', but you probably >>> figured that out already. >> >> Actually, I thought you meant document.all in FF quirks mode. ;) > > Fair enough, that will do as your third example of a host object - > typeof - oddity that can be stated. (Which reminds me, there is (or was, > as it has been criticised) something in Safari that claims to be > 'undefined' even though it can be shown to exist (be an object or > function). I don't recall the detail, but I think Garrett may be in a > position to say what it is (without looking it up in the ES 4/3.1 > mailing list archives.)) > Was an SVG "filter" style property, as a string value:- typeof el.style.filter "undefined". javascript:var s=document.body.style;alert([typeof s.filter,"filter"in s]); elerts "undefined, true" -- Garrett comp.lang.javascript FAQ: http://jibbering.com/faq/
From: David Mark on 15 Nov 2009 02:30 On Nov 15, 1:35 am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote: > Richard Cornford wrote: > > David Mark wrote: > >> On Nov 14, 11:55 pm, Richard Cornford wrote: > >>> Richard Cornford wrote: > >>>> ... After all, you can show them the environments where > >>>> objects result in 'undefined'... > > >>> That 'undefined' should have been 'unknown', but you probably > >>> figured that out already. > > >> Actually, I thought you meant document.all in FF quirks mode. ;) > > > Fair enough, that will do as your third example of a host object - > > typeof - oddity that can be stated. (Which reminds me, there is (or was, > > as it has been criticised) something in Safari that claims to be > > 'undefined' even though it can be shown to exist (be an object or > > function). I don't recall the detail, but I think Garrett may be in a > > position to say what it is (without looking it up in the ES 4/3.1 > > mailing list archives.)) > > Was an SVG "filter" style property, as a string value:- > > typeof el.style.filter > > "undefined". > > javascript:var s=document.body.style;alert([typeof s.filter,"filter"in s]); > > elerts "undefined, true" Right. The collection item method is IE and "string". So to sum up, typeof for native objects is specified and all known implementations follow the specification in this regard (and would be broken as designed otherwise). The allowed results do not include "array". Host objects are allowed to return anything, but save for one case, they return native type names (and the exception is not "array" either). And it would be a dubious assumption that a host object returning typeof "array" means that the object is an Array (certainly document.all !== undefined in FF quirks mode). It's not 100%, but proof enough for me that the code in question is at best superfluous (for native objects) and could be harmful (for host objects). As Richard has speculated (for some time), it is likely the result of a misconception that has spread over the years (programming by copying patterns can produce oddities like this). I've certainly seen this particular example in a lot of scripts. I'll give it to jQuery that they didn't demand "proof" for this one. Of course, there's that pesky attribute "question". And now I see they actually use window.eval. Whatever.
From: Garrett Smith on 15 Nov 2009 02:41
David Mark wrote: > On Nov 15, 1:35 am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote: >> Richard Cornford wrote: >>> David Mark wrote: >>>> On Nov 14, 11:55 pm, Richard Cornford wrote: >>>>> Richard Cornford wrote: >>>>>> ... After all, you can show them the environments where >>>>>> objects result in 'undefined'... >>>>> That 'undefined' should have been 'unknown', but you probably >>>>> figured that out already. >>>> Actually, I thought you meant document.all in FF quirks mode. ;) >>> Fair enough, that will do as your third example of a host object - >>> typeof - oddity that can be stated. (Which reminds me, there is (or was, >>> as it has been criticised) something in Safari that claims to be >>> 'undefined' even though it can be shown to exist (be an object or >>> function). I don't recall the detail, but I think Garrett may be in a >>> position to say what it is (without looking it up in the ES 4/3.1 >>> mailing list archives.)) >> Was an SVG "filter" style property, as a string value:- >> >> typeof el.style.filter >> >> "undefined". >> >> javascript:var s=document.body.style;alert([typeof s.filter,"filter"in s]); >> >> elerts "undefined, true" > And: javascript:var s=document.body.style;prompt('',[typeof s.filter, s]); results: undefined,[object CSSStyleDeclaration] > Right. The collection item method is IE and "string". So to sum up, > typeof for native objects is specified and all known implementations > follow the specification in this regard (and would be broken as > designed otherwise). Ah, not completely. We recently discussed callable regexp. In Spidermonkey typeof /a/ results "object" (where it should, by following the typeof table, result "function". This is because RegExp is callable in Spidermonkey, using Function Call syntax as: /a/("a");// results ["a"] javascript: alert( /a/("a") ) elerts "a" -- Garrett comp.lang.javascript FAQ: http://jibbering.com/faq/ |