1

In a browser experience, programmed constructors are used to generate artifacts in that environment.

  • Is there a comprehensive list of all the predefined primitive constructors?
  • Are some constructors unique to a particular browser (Chrome, Opera, Safari, ...)?
  • Are each constructor's argument types, order and meaning identical among the browsers?

Using FireFox for instance:

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"));

generates: (artifacts with vacuous content are invisible)

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]

What other elementary constructors does FireFox have, if any?

references:
Where is the Documentation for all of the Javascript HTML Element Constructors?
Where are constructors such as, `new Image()` and `new Option()`, documented?
The following missing references were an oversight. Thanks to TeslaNick's answer for prompting their inclusion.
Global Object constructors - MDN Docs
constructor - MDN Docs

Community
  • 1
  • 1
Ekim
  • 949
  • 1
  • 8
  • 9

1 Answers1

0

The Mozilla Developer Center on Javascript is a common reference point for core javascript constructors. The DOM Reference section contains a lot of the stuff specific to the browser environment.

There are more constructors, documented in various sections throughout the MDC. SVG, XUL, Canvas, WebGL, and others all have their own APIs and expose their own objects.

Nick Husher
  • 1,909
  • 11
  • 13
  • What are they and where exactly? ie. https://developer.mozilla.org/en/DOM/FileReader is one – Ekim Aug 07 '11 at 00:34
  • Here are a few more: XMLHttpRequest, Worker, Storage, Audio, XPCNativeWrapper, ... Do all predefined constructors start with a capital letter? – Ekim Aug 07 '11 at 01:29
  • That's a good rule of thumb, yes. In Javascript, *any* function might be a constructor, a utility function, or both; it all depends on how it's used. Note that some constructors probably shouldn't be used: You never want to do `var n = new HTMLDivElement()`, you should do `var n = document.createElement('div')`. Out of curiosity, why do you need to know what all the JS constructors are? – Nick Husher Aug 08 '11 at 15:46
  • A list of "top level" predefined, primitive, objects (this therefore includes functions, and by virtue of being functions, this includes constructors - but see http://stackoverflow.com/questions/6988064/why-are-some-javascript-constructors-not-functions) is handy to avoid "clobbering" the same. A list also facilitates enumerating browser version differences. – Ekim Aug 08 '11 at 20:34