Jul*_*ian 2 javascript scope settimeout
所以,问题是我在一个需要由setTimeout调用的函数内部有一个函数.但这不起作用,因为setTimeout将假定它调用的函数将root作为其范围.
知道如何在不改变功能范围的情况下解决这个问题吗?
编辑:
这就是我的意思:
function general(){
function saysomething(){
console.log('hi there');
}
setTimeout("saysomething();", 1000);
}
Run Code Online (Sandbox Code Playgroud)
setTimeout失败..
function general(){
function saysomething(){
console.log('hi there');
}
setTimeout(saysomething, 1000);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14578 次 |
| 最近记录: |