我是编程新手,刚开始学习JavaScript。当试图创建一个对象打印出来时,Firebug不断给我一些错误代码
参数列表之后SyntaxError:missing)
这是什么意思?我的代码中没有发现问题。
var player1 = {
name: "fred",
score: 1000,
rank: 1
};
var player2 = {
name: "Sam",
score: 10000000,
rank: 5
};
function playerDetails() {
console.log(this.name + "has a rank of" this.rank + "and a score of" + this.score);
};
player1.logDetails = playerDetails();
player2.logDetails = playerDetails();
player1.logDetails();
答案 0 :(得分:3)
首先。尝试更轻松的事情。
var player1 = { name:"fred", score: 1000, rank: 1 };
var player2 = { name: "Sam", score:10000000, rank: 5 };
function playerDetails (player) {
console.log(player.name + "has a rank of" + player.rank + "and a score of" + player.score);
};
playerDetails(player1);
playerDetails(player2);