There's a small test. I expect both obj\d
object have their a
menmber changed in the end. However the change1
style doesn't work, I wonder why, or why not, should it behave like this?
<button id="btn1" onclick="test()">Change</button>
<script>
var obj1 = { a : {strblahblah: "blah"} };
var obj2 = { a : {strblahblah: "blah"} };
function test(){
change1(obj1.a);
change2(obj2);
alert("obj1: " + obj1.toSource() + "\r\nobj2: " + obj2.toSource());
}
function change1(obj){
obj = {str: "change1"};
}
function change2(obj){
obj.a = {str: "change2"};
}
</script>
Result(after you click the button):
obj1: ({a:{strblahblah:"blah"}})
obj2: ({a:{str:"change2"}})