Re: 物件傳遞問題

看板Ajax作者 (銀色)時間17年前 (2008/01/14 17:59), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/5 (看更多)
※ 引述《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
文章代碼(AID): #17YpAGui (Ajax)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 5 篇):
0
2
1
1
文章代碼(AID): #17YpAGui (Ajax)