我正在codecademy.com上一些JavaScript / jQuery的课程。通常,这些课程提供了答案或提示,但是对于这一课程它没有任何帮助,我对说明感到有些困惑。
它说要使函数makeGamePlayer返回带有三个键的对象。
//First, the object creator
function makeGamePlayer(name,totalScore,gamesPlayed) {
//should return an object with three keys:
// name
// totalScore
// gamesPlayed
}
我不确定是否应该这样做
//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;
}
或类似的东西
//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;
}
}
创建对象后,我必须能够修改其属性。
new关键字调用它时,我建议使用大写字母开头该名称MakeGamePlayer。