Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a specification for JavaScript Image object? [duplicate]

Tags:

javascript

dom

Not at Mozilla but:

  • for image:
    Thanks to Rickard for identifying
    http://www.w3.org/html/wg/drafts/html/CR/embedded-content-0.html#dom-image
    that provides the DOM interface constructor details.
  • for option:
    http://www.w3.org/html/wg/drafts/html/CR/forms.html#dom-option
    also gives the DOM interface constructor details.
    (Found using:
    http://www.google.com/search?client=ubuntu&channel=fs&q=constructor+site%3Adev.w3.org%2Fhtml5&ie=utf-8&oe=utf-8)

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,

  • Image() defined at http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.3/reference/image.html
  • Option() defined at http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.3/reference/option.html

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:

  • HTMLImageElement Mozilla documentation
  • Contemporary precedent for Image() constructor use at Mozilla
  • Stack Overflow related question

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.

like image 738
Ekim Avatar asked Aug 04 '11 04:08

Ekim


People also ask

Why is my img tag not working?

Img src Not Working That means, when a web page loads, the browser has to retrieve the image from a web server and display it on the page. The broken link icon means that the browser could not find the image. If you've just added the image, then check that you included the correct image URL in the source attribute.

What are the attributes of IMG tag?

The <img> tag has two required attributes: src - Specifies the path to the image. alt - Specifies an alternate text for the image, if the image for some reason cannot be displayed.

What is image () in JavaScript?

Image() The Image() constructor creates a new HTMLImageElement instance. It is functionally equivalent to document. createElement('img') .


2 Answers

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.

like image 156
RobG Avatar answered Oct 06 '22 00:10

RobG


FWIW Microsoft has documentation for both these constructors on MSDN:

  • Image
  • Option
like image 25
Simon Lieschke Avatar answered Oct 05 '22 23:10

Simon Lieschke