Why is document.getElementById considered an objec

2019-05-11 22:11发布

问题:

I noticed that document.getElementById is a function in Firefox and Chrome, while typeof considers it an object in IE8 (at least).

Anyone has an idea why?

回答1:

IE8 (attempts to) implement ECMAScript 3 where the typeof operator result is implementation defined for host objects regardless if the object implements [[call]]. In ES5, callable host objects must return "function".

See the table in ECMAScript 3

Compare to ECMAScript 5.1 http://www.ecma-international.org/ecma-262/5.1/#sec-11.4.3