Get Programming with JavaScript - Listing 14.01
Listing 14.01 - The User Constructor
var User = function (name) {
var sessions = [];
var totalDuration = 0;
this.addSession = function (sessionDate, duration) {
sessions.push({
"sessionDate" : sessionDate,
"duration" : duration
});
totalDuration += duration;
return totalDuration;
};
this.getData = function () {
return {
"name" : name,
"total" : totalDuration,
"sessions": sessions.slice()
};
};
};