Open H246802 opened 5 years ago
第一种 直接函数通过return 解决
function fn(){
console.log('a')
return function(){
console.log('b')
return function(){
console.log('c')
}
}
}
第二种 通过异步代码实现
function fn(){
var x = 'a'
var time = setTimeout(()=> console.log(x),0)
return function(){
x = 'b'
return function(){
clearTimeout(time)
console.log('c')
}
}
}
写一个函数
fn
,使得fn
满足一下条件fn()
打印出'a'
fn()()
打印出'b'
fn()()()
打印出'c'