estoy tomando algunas clases de JavaScript/jQuery en codecademy.com. Normalmente, las lecciones proporcionan respuestas o pistas, pero para esta no da ninguna ayuda y estoy un poco confundido por las instrucciones.JavaScript: función que devuelve un objeto
Se dice que hacer la función makeGamePlayer devolver un objeto con tres teclas.
//First, the object creator
function makeGamePlayer(name,totalScore,gamesPlayed) {
//should return an object with three keys:
// name
// totalScore
// gamesPlayed
}
No estoy seguro de si debería estar haciendo esto
//First, the object creator
function makeGamePlayer(name,totalScore,gamesPlayed) {
//should return an object with three keys:
// name
// totalScore
// gamesPlayed
this.name = name;
this.totalScore = totalScore;
this.gamesPlayed = gamesPlayed;
}
o algo así
//First, the object creator
function makeGamePlayer(name,totalScore,gamesPlayed) {
//should return an object with three keys:
// name
// totalScore
// gamesPlayed
var obj = {
this.name = name;
this.totalScore = totalScore;
this.gamesPlayed = gamesPlayed;
}
}
Tengo que ser capaz de modificar las propiedades del objeto después de su creado.
@OP también tenga en cuenta que cuando vaya a invocarlo con la palabra clave 'new' sugeriría comenzar el nombre con una letra mayúscula:' MakeGamePlayer'. – PeeHaa
@ Oriol: comprueba el objeto literal, tiene errores de sintaxis. – RobG
@PeeHaa Un buen consejo, también la convención de nomenclatura más típica cuando se usa el constructor sería 'nuevo GamePlayer()'. –