导航栏: 首页 评论列表

HTMLElement prototype title Uncaught TypeError: Illegal invocation

默认分类 2018/10/25 07:26

感慨一下,从事IT行业,知识的更新迭代速度非常之快,每天都有可能会颠覆昨天学到的知识。

let aa = {}; console.log(aa.title);
> undefined

如上按说在JS中只要aa不是null或undefine,上面这段代码是不应该报错的,过去这么认为,没什么问题, 要现在还这样认为那就错了,猜猜下面这段代码输出什么?

class kkk extends HTMLElement {
  constructor() {
    super() 
  }
}
kkk.prototype.title

在chrome下输出

Uncaught TypeError: Illegal invocation
  at <anonymous>:6:15

在firefox下输出

TypeError: 'get title' called on an object that does not implement interface HTMLElement.


>> 留言评论