ฉันกำลังเรียนบทเรียน JavaScript / jQuery ที่ codecademy.com โดยปกติบทเรียนจะมีคำตอบหรือคำใบ้ แต่สำหรับบทเรียนนี้ไม่ได้ให้ความช่วยเหลือใด ๆ และฉันสับสนเล็กน้อยกับคำแนะนำ
มันบอกว่าจะทำให้ฟังก์ชัน 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;
}
}
ฉันต้องสามารถปรับเปลี่ยนคุณสมบัติของวัตถุหลังจากที่สร้างขึ้น
newMakeGamePlayer