var person={
name:'aaa'
}
with(person){
var name='bbb';
var age='27';
alert(name);//bbb
alert(age);//27
}
alert(name);//undefined
alert(age);//27
with(location){
var href="ccc";
alert(href);//file://E:test.html
}
alert(href);//undefined
------解决方案-------------------- with语句很特殊而且不被推荐使用,解析 var person = { name: 'aaa' } with(person) { var name = 'bbb';//语句1 var age = '27';//语句2,创建变量age alert(name === person.name);//true } 内部创建的name指针指向了person.name,等价于: person.name = 'bbb';//语句1 var age = '27';//语句2
var person = new Object();
person.name="jim";
with(person) {
var name = 'bbb';//语句1
var age = '27';//语句2,创建变量age
alert(name === person.name);//true
}
------解决方案--------------------