Here is the code that made this page run:
//First, we make a class, using object properties to describe each object....
function Song(name, year, timesPlayedThusFar) {
this.name = name;
this.yearRecorded = year;
var timesPlayed = timesPlayedThusFar;
//Here is the public method to call a private variable
this.TimesSongPlayed = function() {
return(timesPlayed);
};
};
// Make a new object
var WildThing = new Song("Wild Thing", 1966, 30);
//Create a variable that calls the public method to fetch the private variable
var FetchTimesPlayed = WildThing.TimesSongPlayed();
//Print the result to an alert when called...
var announce = function(){
alert(FetchTimesPlayed);
}