<script language="javascript"> //dosomething1,对于引用,变量本身不可以修改,但变量内部结构可以修改 function dosomething1(a){ a = 'try'; }
//测试1 function test1(){ var a = {a:'test',b:'is',c:'ok'}; dosomething1(a); alert(a.a); } //dosomething2 function dosomething2(v){ v.a = v.a + '!!!'; //修改引用变量的属性,修改成功 v = 'try'; //试图修改变量引用,修改失败 } //测试2 function test2(a){ var a = {a:'test',b:'is',c:'ok'}; dosomething2(a); alert(a.a); } test2(); </script>