I am learning to program, the question I have is the following,
What happens when you write the code in this way? (background.image = new Image ();) - Why "new Image"? -What happens with the original "Image"?
Greetings!
The first thing I would recommend is that you read a bit about how language works, and about object theory (not POO, here there is no such thing).
Js is a bit complicated for some things, and mixes concepts without making clear where things are coming from.
There is no% previous IMAGE
. Simply, because IMAGE
in that scope is an object and you are applying it to fondo.imagen
.
That line what it says is:
In fondo.imagen
, it puts a new object of type IMAGE
.
That does not mean that it destroys IMAGE
or that it does something else, what it does is pass it a reference to a new object (created recently, with the new
) to that property of that object that you decide.
It may sound complicated, and it is if you do not have knowledge of how the objects work.