The second way is the same image.
If you say that:
b = a;
c = b;
And if a is an object, then b and c are just references which point to the same object.
How about making a function to load an image?
function loadImage(name, optionalCallback) {
var img = new Image();
if (typeof optionalCallback === "function") { img.onload = optionalCallback; }
img.src = name;
return img;
}
Then you can say:
var a = loadImage("images/image01.png", function () { document.body.appendChild(this); }),
b = loadImage("images/image02.jpg", function () { gallery.addImage(this); });
There's a lot more that you can do with this, when you get further along -- when you get into Promises and whatnot, you can do an awful lot with those images.
Also, you might want to be careful if you're writing a program that looks like:
var a = new Image();
a.src = "images/image01.jpg";
document.getElementById("gallery").appendChild(a);
If you get to the part of the code where you're adding the image to the page, before the image is done loading, then you might get unexpected results.