用`createElement`创建一个`object`标签返回一个函数而不是一个对象 [英] Creating an `object` tag with `createElement` returns a function instead of an object

查看:234
本文介绍了用`createElement`创建一个`object`标签返回一个函数而不是一个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  typeof document.createElement('div')可以有人解释为什么我创建不同的元素时会得到不同的类型
object
typeof document.createElement('span')
object
typeof document.createElement('embed')
function
typeof document.createElement('object')
函数

这些都是在firefox :

  $ firefox --version 

(process:9436):GLib-CRITICAL **: g_slice_set_config:assertion'sys_page_size == 0'failed
Mozilla Firefox 32.0.3


解决方案

ES5规范状态< a>实现 [[Call]] 的对象必须报告为 typeof 函数



少量DOM元素(对象 embed ,不是很多其他) 可调用/执行 [[Call]] 。这可能是出于历史原因,但事实依然是您可以调用它们。



所以Firefox在技术上将其报告为功能秒。事实上,你可以认为Chrome等是错误的(如果严格遵守ES5规范)将其报告为对象,因为它们也可以在这些浏览器中调用。另一方面,这些浏览器正在做大多数人可能会期待的。



更多详细信息在 Bugzilla


Could someone explain why I am getting different types when creating different elements?

typeof document.createElement('div')
"object"
typeof document.createElement('span')
"object"
typeof document.createElement('embed')
"function"
typeof document.createElement('object')
"function"

These are on firefox:

$ firefox --version

(process:9436): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
Mozilla Firefox 32.0.3

解决方案

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 functions. You could, in fact, argue that Chrome et al. are wrong (if sticking strictly to the ES5 spec) to report them as objects, 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.

这篇关于用`createElement`创建一个`object`标签返回一个函数而不是一个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆