我想引用一個數組中的索引,但gameObjects [1]返回爲undefined。 gameObjects是一組對象。你不能連接一個字符串與一個JavaScript對象中的函數調用?
var gameObjects = [enemy,treasure];
var mysteryBlock = {
name: "Mystery Block",
output:"produces " + gameObjects[1]
}
var enemy = {
output: "an enemy"
}
var treasure = {
output: "a treasure"
}
console.log("your mystery cube " + mysteryBlock.output)
回到未定義狀態。
也許你的意思'輸出: 「生產」 + gameObjects [1] .output' – bejado
在哪裏,函數調用你的稱號指什麼? – Lucero