When using ECMAScripts typeof
on plugin elements (i.e. embed
or object
), Safari & FireFox return "function"
:
typeof(window.document['myPlugin']) // "function"
This can't be influenced on the plugin side开发者_运维百科, as the browser doesn't call the plugin here. Funny enough, in IE the same line evaluates to "object"
.
Is that simply implementation dependent behaviour as per ECMAScript §11.4.3 or am i missing something here?
The specs are all very vague when it comes to how typeof should behave with a plugin object, since ECMAScript wasn't written with plugins in mind. Hence on IE with an activex control it will tend to respond with "object" because that's how they decided to deal with it; Firefox and I believe Safari both respond with "function" because that is how they determined to deal with it.
Both answers make sense; remember that when you access the plugin with document.getElementById("myPlugin"), you aren't just getting a reference to the plugin, you're getting a reference to the HTML element that hosts the plugin, which happens to proxy calls to the plugin. Being an HTML element, it has other properties and methods that you don't even know about.
It does seem like object would make more sense in this case, but an object generally does not, cannot have a default function, and so my guess is that firefox determined to respond that it is a function() because there is no way in the NPAPI to query to see if the default function exists, short of calling InvokeDefault. while you can call a default method on an ActiveX IDispatch interface as well, it really seems more like an incidental side-effect than a design feature.
Not a terribly scientific answer, but one that might help.
精彩评论