- 函数在执行的过程中,先从自己内部找变量;
- 如果找不到,再从创建当前函数所在的作用域去找,依此往上;
- 注意找的是变量的当前的状态
var a = 1
function fn1(){
function fn3(){
function fn2(){
console.log(a)
}
fn2()
var a = 4
}
var a = 2
return fn3
}
var fn = fn1()
fn() //输出多少 //undefined
var a = 1
function fn1(){
function fn3(a){
function fn2(){
console.log(a)
}
fn2()
a = 4
}
var a = 2
return fn3
}
var fn = fn1()
fn(5) //输出多少 5
var a = 1
function fn1(){
function fn3(){
var a = arguments[0] //相当于
function fn2(){
console.log(a)
}
fn2()
a = 4
}
var a = 2
return fn3
}
var fn = fn1()
fn(5) //输出多少
网友评论