1.1.1.Pass array by value
Last updated
Was this helpful?
Last updated
Was this helpful?
在js中, 將array傳入function中做運算若沒有經過處理將會以pass by reference傳入, 因此當在function中的array內容被改變, 將會影響原本的array
為了避免此情況, 可以將array以pass by value的方式傳入, 以避免污染原有的array
pass by reference v.s. pass by value
native array method - "slice()" will return a shallow copy of the array.