Could someone explain why I am getting different types when creating different elements?
typeof document.createElement(\'div\')
\"object\"
typeof document.cr
The ES5 spec states that an object that implements [[Call]]
must be reported as typeof
"function"
.
A small handful of DOM elements (object
, embed
, not many others) are callable / do implement [[Call]]
. This is likely for historical reasons, but the fact remains that you can call them.
So Firefox is technically correct in reporting them as function
s. You could, in fact, argue that Chrome et al. are wrong (if sticking strictly to the ES5 spec) to report them as object
s, since they are callable in those browsers too. On the other hand, those browsers are doing what most people would probably 'expect'.
More details are in Bugzilla.