function setName(obj){
obj.name = "obama";
obj = {name:"clinton"};
}
var president = {name:"bush"};setName(president);执行完只段代码以后president.name的值为什么是"obama"记得javascript高级程序设计中讲过,就是忘记在哪页了
1 回答
阿晨1998
TA贡献2037条经验 获得超6个赞
一句一句的分析代码:
var president = {name:"bush"};president指向{name:"bush"}对象
setName(president);
将obj指向president指向的对象, 也就是{name:"bush"}
obj.name = "obama";
将obj指向的对象(也就是president指向的对象)的name属性值改为"obama"
obj = {name:"clinton"};把obj的指向从{name:"obama"}对象改为了{name:"clinton"}对象
而president仍然指向{name:"obama"}对象
添加回答
举报
0/150
提交
取消
