The Image()
constructor creates a new HTMLImageElement
instance. It is functionally equivalent to document.createElement('img')
.
The only difference between
new Image()
and
document.createElement('img')
is that one line is shorter than the other.
However, your two code blocks have other differences as well. Your first block stores the image in the
page.data
object, whereas the second block stores it in a local variable.
And neither block is entirely correct. You should assign the
onload
handler
before assigning the
src
.