Where are constructors such as, `new Image()` and `new Option()`, documented?
Asked Answered
A

4

40

Not at Mozilla but:

Given these references, it is moot whether mozilla.org, as asked below, documents the same.


Specifically, where at mozilla.org are constructors like new Image() and new Option() documented in a contemporary context?

Archaic documentation,

describes the existence of these constructors implicating them as intrinsic JavaScript language components, which is incorrect.

javascript: alert([new Image(), '\n\n', new  Option()])

clearly indicates their manifest existence by displaying

[object HTMLImageElement],

,[object HTMLOptionElement]

Rhetorically, what about:

javascript:alert([new Anchor(), new Preserve(), new Form(),,, ])

What other primitive elemental DOM constructors are there? Or, are there no more?

Is it anathema to, and inconsistent with the DOM paradigm used by Mozilla, to incorporate the programming definitions of new Image() and new Option() etc., explaining their absence? Yet, these constructors are clearly not intrinsic to the language specification of JavaScript and certainly not HTML. So, where exactly is there a correct current paradigm (originating from mozilla.org) that describes them fully, including argument types and orders?

references:


An aside: (please do not be distracted by this - locating the relevant documents as specified in the article's title is the only consideration)

This answer prompted the following examination. It is only an observation.

javascript:
    alert([  Option, Image,
               JSON, Math, Error, 
                 Array, Boolean, Date, Function,
                   Number, Object, RegExp, String  ].join("\n\n"));
    alert( Image.toSource() );

produces in FireFox:

[object Option]

[object Image]

[object JSON]

[object Math]

function Error() { [native code] }

function Array() { [native code] }

function Boolean() { [native code] }

function Date() { [native code] }

function Function() { [native code] }

function Number() { [native code] }

function Object() { [native code] }

function RegExp() { [native code] }

function String() { [native code] }

and

({})

but

Error: ({}) is not a constructor
Source File: javascript:alert(new ({}));
Line: 1

Is Image a constructor or not? The answer to this would (presumably) be found in the documents that answer the question asked in this posting's title. This should emphasize the inconsistencies, anomalies and irregularities of cataloging Image and Option etc. in an appropriate document.

Ashil answered 4/8, 2011 at 4:7 Comment(3)
You can always see the spec at w3, see dev.w3.org/html5/spec/spec.html and dev.w3.org/html5/spec/embedded-content-1.html#the-img-element for HTML5 and w3.org/TR/html401 for htmk 4.01.Gorblimey
I think you're confused. JavaScript™ is owned and defined by Mozilla, they can specify that it contains whatever they like. The generic term "javascript" (with various capitalisations) is used to describe ECMAScript implementations in browsers that implement (among other things) the W3C DOM interfaces. It is very common for javascript in browsers to implement far more features that are specified by the W3C. Noting also that nearly all the W3C specs are language neutral and are not specifically for javascript (HTML5 is an exception, but it is not a W3C standard).Sulphurous
No confusion - just rhetorically emphasizing the lack of rigor and formality in the Mozilla Documents for Image() etc. so conveniently glossed over for the very reasons outlined. Once formally documented (circa late 1990's) in the 1.3 version references, but now conspicuously absent, the unqualified constructors are prevalent even at Mozilla's own site: developer.mozilla.org/en/Canvas_tutorial/… - so where ARE they formally described and documented?Ashil
S
10

There is a distinction between JavaScript™ (the implementation of ECMAScript for DOM manipulation by Mozilla, aka Gecko) and the generic term "javascript" that is used to describe similar scripting environments in other browsers (e.g. JScript in IE).

Archaic documentation, [...] describes the existence of these constructors implicating them as intrinsic JavaScript language components, which is incorrect.

How do you come to that conclusion? JavaScript™ belongs to Mozilla so they can specify that it contains whatever they want. JavaScript™ has had an Image and Option constructor since the very beginning, other implementations have copied them so that every browser in existence has them. Such features existed before the creation of the W3C DOM interfaces and, where ubiquitous, are labelled "DOM 0", which really means were supported by Netscape Navigator and Internet Explorer at the time of DOM 1.

DOM 0 is not officially documented anywhere. HTML5 is an attempt at writing a specification for HTML and javascript as is implemented in browsers, so it includes both the Image and Option constructors and so includes DOM 0 features, but they aren't labelled or classified as such.

[...]

Yet, these constructors are clearly not intrinsic to the language specification of JavaScript

There is no published specification for JavaScript™, there is only the JavaScript documentation at Mozilla Developer Network (MDN). Also note that the documentation at MDN is a public wiki that anyone can create and edit, including you. :-)

You are mistaken in believing that the documentation at Mozilla is some kind of complete specification for JavaScript™—it isn't. Not by a long way. It is really just documentation that has been added by interested persons, mostly by poking around the browser and seeing what it does. There is also a JavaScript Reference, but you may also find that lacking.

[...]

HTMLImageElement Mozilla documentation

That link to the the Gecko DOM reference documents the JavaScript implementation of the W3C HTMLImageElementInterface which does not have an Image constructor.

Contemporary precedent for Image() constructor use at Mozilla

Which indicates that it exists, but there is no convenient place to document it. It might be best documented in the JavaScript Reference. If you wish to add it, get an MDN account (free, very easy) and add it.

Edit

There is now an Image article at MDN that links to relevant standards.

Edit 25 May 2015

The Option constructor is documented in HTML5.

Sulphurous answered 4/8, 2011 at 5:7 Comment(5)
The two constructors (Image(), Option()) DO NOT fit the generic Mozilla JavaScript paradigm otherwise they would still be resident in the current developer.mozilla.org/en/JavaScript documents. A similar case is the document.createElement() which IS a DOM concept and not a JavaScript language component. They are intrinsically bound to the Object Model for a Document. Irregardless - at this point my question obviously is completely rhetorical as it appears they ARE NOT documented in any current formal Mozilla specifications, not even for possible deprecation.Ashil
The concepts and delineation of the paradigms described by JavaScript, DOM and HTML are made explicit in Mozilla's documentation. The constructors like new Image(width, height) (height, width? or where is the document specifying the order?) don't 'fit' those defined paradigms and their definitions are missing from the current documents.Ashil
"There is no published specification for JavaScript™"? Quoting JavaScript -MDN Docs there is a section: JavaScript Language Resources A description of the JavaScript language standards.Ashil
@ekim - that link is to ECMAScript standards, not JavaScript™. There is published documentation for JavaScript™, but there is no standard.Sulphurous
" ... JavaScript Language Resources A description of the JavaScript language standards ... " is a verbatim quote at the bottom of the page from JavaScript -MDN DocsAshil
T
2

FWIW Microsoft has documentation for both these constructors on MSDN:

Turbit answered 31/10, 2011 at 5:40 Comment(0)
A
1

HTML 5

DOM Option class

http://dev.w3.org/html5/spec-preview/the-option-element.html

Several constructors are provided for creating HTMLOptionElement objects (in addition to the factory methods from DOM Core such as createElement()): Option(), Option(text), Option(text, value), Option(text, value, defaultSelected), and Option(text, value, defaultSelected, selected).

Agamemnon answered 23/7, 2013 at 11:22 Comment(0)
L
-1

Actually, I never had to use the constructor arguments. I just create the object and fill the members afterwards.

var img=new Image();
img.src="path/to/image.jpg";

When I "meet" a new class in Javascript, I explore it using JSON.stringify and by using a piece of code like this:

var obj_to_explore=new Image();
var dbg=[]
for(var i in obj_to_explore){
    dbg.push(i+": "+obj_to_explore[i]);
}
//alert("explored object: " + dbg.join(", "))
console.log("explored object: " + dbg.join(", "));

Because it's much easier to find (on google) information on specific member names than on a feature description.

Lanai answered 4/8, 2011 at 4:23 Comment(2)
That was NOT my question - and JSON can not explore Image, the function, only it's manifest object new Image() and thus, for example, gives no hint as to the order and type of arguments used by the Image Function.Ashil
Thanks for the commentary. The posting has been augmented accordingly with similar considerations. I prefer using FireFox's .toSource() which is more versatile than JSON and .stringify() (recursive, functional etc.).Ashil

© 2022 - 2024 — McMap. All rights reserved.