在浏览器体验中,编程的构造函数用于在该环境中生成工件。
- 是否有所有预定义基元构造函数的完整列表?
- 某些构造函数是否是特定浏览器(Chrome、Opera、Safari...)所独有的?
- 每个构造函数的参数类型、顺序和含义在浏览器中是否相同?
以 FireFox 为例:
javascript:
alert([
"using browser environment: \n"+window.navigator.userAgent,
new Array(), new Boolean(), new Date(), new Function(),
new Number(), new Object(), new RegExp(), new String(),
new Error(), new Image(), new Option(),
] . join("\n\n"));
生成:(内容空洞的工件是不可见的)
using browser environment:
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3
false
Fri Aug 05 2011 11:25:15 GMT-0400 (EST)
function anonymous() { }
0
[object Object]
/(?:)/
Error
[object HTMLImageElement]
[object HTMLOptionElement]
FireFox 还有哪些其他基本构造函数(如果有)?
引用文献:
Where is the Documentation for all of the Javascript HTML Element Constructors?
Where are constructors such as, `new Image()` and `new Option()`, documented?
以下缺失的引用文献是一个疏忽。感谢TeslaNick's answer促进他们的加入。
Global Object constructors - MDN Docs
constructor - MDN Docs
最佳答案
Mozilla Developer Center on Javascript是核心 javascript 构造函数的公共(public)引用点。 DOM Reference部分包含许多特定于浏览器环境的内容。
还有更多的构造函数,记录在整个 MDC 的各个部分中。 SVG、XUL、Canvas、WebGL 等都有自己的 API 并公开自己的对象。
关于javascript - 什么是预定义的原始构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6961019/