Quantcast
Channel: 2D Latest Topics
Viewing all articles
Browse latest Browse all 623

use single var for multiple new Image()

$
0
0

 Hi.

I was testing to see if I could use the following code to store new Image() in a variable and use it for several images.

var _new_image = new Image();

var _image_1 = _new_image;
_image_1.src = "./assets/views/image_1.jpg";

var _image_2 = _new_image;
_image_2.src = "./assets/views/image_2.jpg";

var _image_3 = _new_image;
_image_3.src = "./assets/views/image_3.jpg";

So each new image created uses the _new_image variable instead of new Image() . But, of course, this isn't working. Only one image will load.

So I was wondering if I can store new Image() in a variable and what the syntax/code would be to do this.

Thanks.

 

 

 


Viewing all articles
Browse latest Browse all 623

Trending Articles