Most computer languages have the idea of defining your own "
objects" (called a "class" in some languages) that let you wrap all the details up.
Imagine if we wanted to have three different watermelons on-screen at the same time.
Compare this:
var melon1_x = 10;
var melon1_y = 10;
var Melon1Img = new Image();
Melon1Img.src = "http://s2js.com/img/etc/melon1.png";
var melon2_x = 50;
var melon2_y = 50;
var Melon2Img = new Image();
Melon2Img.src = "http://s2js.com/img/etc/melon2.png";
var melon3_x = 10;
var melon3_y = 90;
var Melon3Img = new Image();
Melon3Img.src = "http://s2js.com/img/etc/melon3.png";
With this:
var melon1 = new Melon(10, 10, "http://s2js.com/img/etc/melon1.png");
var melon2 = new Melon(50, 50, "http://s2js.com/img/etc/melon2.png");
var melon3 = new Melon(10, 90, "http://s2js.com/img/etc/melon3.png");
Or even better, having an array of melons.!