Javascript
function User (theName, theEmail) {
var FLAG = 9; // PRIVATE VARIABLE
this.name = theName;
this.email = theEmail;
this.quizScores = [];
this.currentScore = 0;
// La siguiente función SIRVE PARA RETORNAR ATRIBUTOS PRIVADOS
this.getFlag = function() {
return FLAG;
}
}
User.prototype = {
constructor: User,
saveScore:function (theScoreToAdd) {
this.quizScores.push(theScoreToAdd)
},
showNameAndScores:function () {
var scores = this.quizScores.length > 0 ? this.quizScores.join(",") : "No Scores Yet";
return this.name + " Scores: " + scores;
},
changeEmail:function (newEmail) {
this.email = newEmail;
return "New Email Saved: " + this.email;
}
}
// O TAMBIÉN SE PUEDE UTILIZAR LA SIGUIENTE SINTAXIS:
User.prototype.changeEmail = function (newEmail) {
this.email = newEmail;
return "New Email Saved: " + this.email;
}