views:

45

answers:

1

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?

+1  A: 

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.

Taxilian
After getting `GetValue()` and looking at the definition for native and host object (http://bclary.com/2004/11/07/#a-4.3.6, why didn't i do that before?) it should be a host object and thus *implementation defined* where your reasoning fits well.
Georg Fritzsche