3

playing around with some HTML element I came across a image object declaration

var image = new Image();

Could somebody tell me where this constructor is defined? I have searched ECMAScript and some hmtl specifications...

Regards

Artskee
  • 59
  • 1
  • 4
  • See also [Where are constructors such as, `new Image()` and `new Option()`, documented?](http://stackoverflow.com/questions/6936071/where-are-constructors-such-as-new-image-and-new-option-documented) – Boaz Jan 14 '13 at 10:04

2 Answers2

2

While being well supported across browsers, isn't part of any standard the closest Image() comes to being part of a standard is an appearance in the HTML 5 draft. There is some documentation for Image on MDN.

I'd generally recommend using createElement instead as it provides a consistant API for creating any kind of element and is part of the DOM standards.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

It is part of the HTML DOM (not part of ECMAScript), see this link:

Image API

sramzan
  • 96
  • 8
laurent
  • 88,262
  • 77
  • 290
  • 428
  • Do you have a better link? – laurent Jan 14 '13 at 10:03
  • That isn't documentation for the `Image` function, it is for an `HTMLImageElement` object (which is what `Image()` returns). – Quentin Jan 14 '13 at 10:04
  • @Quentin, but since `Image` implements `HTMLImageElement` they have the same API, don't they? – laurent Jan 14 '13 at 10:06
  • A better collection of sources was suggested in a comment to the OP - [Where are constructors such as, `new Image()` and `new Option()`, documented?](http://stackoverflow.com/questions/6936071/where-are-constructors-such-as-new-image-and-new-option-documented). W3schools is an unreliable source of documentation, see [w3fools](http://w3fools.com/) – Boaz Jan 14 '13 at 10:06
  • @Laurent — That's not very good documentation on the part of MDN. `Image` returns an object that implements `HTMLImageElement`. – Quentin Jan 14 '13 at 10:09