有沒有一種方法可以傳遞變量本身,而不是JavaScript中的值?我記得能夠在fla3中這樣做,如果我記得基於javascript的正確。我不確定爲什麼我不能在這裏做同樣的事情。您的幫助將不勝感激。在數組中傳遞變量,而不是javascript中的值
variable1: false, function1() { this.variable1 = true //this works of course console.log(this.variable1) prints true } function2() { var temparray1 = [this.variable1] temparray1[0] = true //does not work like i want, it's the value in the array that change, not this.variable1 console.log(this.variable1) //prints still false console.log(temparray1[0]) //prints true }
你不能那樣做。 – SLaks
這不是該語言應該如何工作的原因,對於任何稍後必須使用代碼的JavaScript開發人員來說,這會非常混亂。 – sbking
[Javascript引用與值的可能重複](https://stackoverflow.com/questions/6605640/javascript-by-reference-vs-by-value) – Nisarg