【发布时间】:2019-07-15 23:31:51
【问题描述】:
我正在 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;
}
}
我必须能够在创建对象后修改其属性。
【问题讨论】:
标签: javascript