看板 Ajax 關於我們 聯絡資訊
※ 引述《tirme (Tirme)》之銘言: : function setObj(obj) { : var newData = {}; : newData.id = "123"; : obj = newData; // obj = main.data : } : The main.setData() alert is undefined. : Change setObj function : : function setObj(obj) { : var newData = {}; : newData.id = "123"; : obj.prop = newData; : } : The main.setData() alert(this.data.prop.id) is "123". : How to modify original setObj function : and main.setData() alert(this.data.id) is "123"? the first setObj is doing `pass by value`, not `pass by reference`. js does not support passing by reference for types such as string, number, or boolean. however, it does automatically pass by reference objects, functions, arrays, HTMLElements and other complex objects -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.135.19.91