- 作用:
將代碼的作用域設置到一個特定的對象中。
2. with語句的語法
with (expression) {
statement;
}
3. 示例
var foo = 1;
var bar = {
foo : 2
}
with (bar) {
alert(foo);
foo = 3;
alert(foo);
var foo = 4;
alert(foo)
}
alert(bar.foo);
alert(foo);
if(true){
foo = 5;
}
alert(foo);
這幾個alert分別打印的是: 2, 3,4,4,1, 5.