Exotic OBJECT?

Claude Pache claude.pache at gmail.com
Tue Aug 12 11:54:37 PDT 2014


Le 12 août 2014 à 18:44, Garrett Smith <dhtmlkitchen at gmail.com> a écrit :

> What's the explanation and reason for this strange characteristic of
> the OBJECT element in Firefox?
> 
> Firefox 31:
> typeof document.createElement("object")
> "function"
> Function.prototype.toString.call(document.createElement("object"));
> TypeError: Function.prototype.toString called on incompatible object
> 
> If the typeof OBJECT results "function" then it either:
> a) implements [[Call]] or
> b) is exotic
> 
> Since calling `Function.prototype.toString` with OBJECT as the this
> value results in a TypeError, it appears that the OBJECT does not
> implement [[Call]] and thus the only explanation is that the OBJECT is
> exotic. Did I get that right? Or is there another explanation?
> 
> What's the explanation and reason for this strange characteristic of
> the OBJECT element in Firefox?

According to comments 10-18 in https://bugzilla.mozilla.org/show_bug.cgi?id=268945 , object and embed elements do implement [[Call]] for some obscure reason. Hence `typeof` yielding "function".

Maybe I'm splitting hairs, but the spec doesn't say explicitly that all objects implementing [[Call]] must support `Function.prototype.toString`, although I'm not sure that that omission was intentional. Anyway, if you want to test if an object implements [[Call]], the best method is simply to try to call it:

	document.createElement("object")()

(which produces an interesting result in Firefox).

—Claude


More information about the es-discuss mailing list