I'm trying to learn javascript from online tutorial.
I don't understand line 12, what does these line of code do? what are outImage, thisImage.outImage, and Image()?Is Image() a javascript built-in object? Is thisImage.outImage an object? or only outImage is an object? Thanks so much, any answers are appreciated.!

1 Answer
Look at line 6.
setupRollover( document.images[i] );
That's calling the function.
function setupRollover (thisImg) { /* ... */ }
So thisImg === document.images[i];
document is a browser built-in object (not built into JavaScript, but one which is put in by every browser), which gives you access to the HTML on the page (aka: The "DOM").
so, document.images is a list of all of the images on the DOM.
var img = new Image( ); img.src = "..."; makes a new image, the same way typing <img src="..."> in the HTML gives you a new image.
The difference is that now you have it in JavaScript and not in HTML, so you can change it and move it around, and pass it to different functions.
The only other confusing piece of the puzzle is that you can attach almost anything to almost anything else in JavaScript.
var img = new Image(),
img2 = new Image();
img.otherImage = img2;
This doesn't do anything special or magic.
It's just, now any time I ask for img.otherImage in that script, it will give me img2.
2 Comments
var img = new Image(), img is an object? how about Image(), is it an object or a class? thanksvar img = new Image( ); so it is the function that makes image objects.
thisImageis the object passed to the function (in this case, an image)outImageis a new property being defined on the object.new Image();is creating a new image. -- Really simple!srcis already a property ofnew Image()objects, so it's just setting an existing property to a new value ;)