在控制檯中放置/更改"property"
與this[property]
有什麼區別,我相信它們都是指同一個表達式,但是當我調用函數時,後者會給我[object,Object]。Javascript對象枚舉
var rockSpearguns = {
Sharpshooter: {barbs: 2, weight: 10, heft: "overhand"},
Pokepistol: {barbs: 4, weight: 8, heft: "shoulder"},
Javelinjet: {barbs: 4, weight: 12, heft: "waist"},
Firefork: {barbs: 6, weight: 8, heft: "overhand"},
"The Impaler": {barbs: 1, weight: 30, heft: "chest"}
};
rockSpearguns["listGuns"] = function(){
for (var property in this) {
if(this[property]["heft"]!==undefined){
console.log("Behold! " + this[property] + ", with " +
this[property]["heft"] + " heft!");
}
}
}
rockSpearguns["listGuns"]();
你問這個[「property」]'和'this [property]'有什麼區別? –
nope,屬性和這[屬性]在控制檯 –