Javascript中的变量怎么会是一个函数,却不能被调用呢?

How can a variable in Javascript be a function, but not be able to be called?

我目前正在调查一个网站,发现了一件奇怪的事情。如果我在开发者控制台中找到一个 PNACL 嵌入元素,并在 Chrome 开发者控制台中评估它,它会记录 > anonymous(),旁边有一个箭头显示它是一个普通的 HTML 元素。但是,typeof temp1(变量名)returnsfunction,但是调用它会抛出

Uncaught TypeError: temp1 is not a function
    at <anonymous>:1:1

并调用 toString() returns "[object HTMLEmbedElement]"> anonymous() 是什么意思,Javascript 变量怎么可能是一个函数却无法调用?

MCVE:
FF

var el=document.createElement("embed"); //<embed>
typeof el;// "function"
el.toString(); //"[object HTMLEmbedElement]"
el(); // [Exception... "Component is not available"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame :: debugger eval code :: <TOP_LEVEL> :: line 1"  data: no]


Chrome

var el=document.createElement("embed"); // anonymous()
typeof el;// "function"
el.toString(); //"[object HTMLEmbedElement]"
el(); //undefined

这是 known bug,我一年前提交过。

受影响的元素:

  • HTMLAllCollection
  • NPObject(?)
  • HTMLObjectElement
  • HTMLEmbedElement

铬团队的回答:

External users have not complained about it, so I'm thinking of Archiving it.

该死的我是一个"external user"...

当前状态:已存档

原因:

这些元素有一个 [Call] 内部方法,因此根据 EcmaScripttypeof 必须 return 'function'(这使得该错误成为规范错误而不是实现错误...)