在javascript中的函数内更改(或)改变函数的作用域
正如问题所说 我想知道如果有一种方法可以改变函数的作用域在javascript中的函数内更改(或)改变函数的作用域,javascript,Javascript,正如问题所说 我想知道如果有一种方法可以改变函数的作用域 function foo(){ var t = this; log(t);//{bar:'baz'} /*** Do something over here to change the scope ***/ var newThis = this; log(newThis); //{something:'somethingelse'} } 我只是想知道,有没有办法 谢谢 不过我不建议你用它 不建议与
function foo(){
var t = this;
log(t);//{bar:'baz'}
/*** Do something over here to change the scope ***/
var newThis = this;
log(newThis); //{something:'somethingelse'}
}
我只是想知道,有没有办法
谢谢
不过我不建议你用它
不建议与一起使用,并且在ECMAScript 5中禁止使用
模式建议的替代方法是指定其
要访问临时变量的属性
function foo(){
log(this);
/*** Do something over here to change the scope ***/
with (newThis) {
log(this);
}
}