代码改变世界

有关于匿名函数跟闭包的一道题

2018-06-22 10:12  改吧  阅读(419)  评论(1编辑  收藏  举报

var demo=(function(a){

this.a=a;//从参数a=4
return function(){

this.a+=a;//this是指向window window=8

return a//这个闭包函数 是可以访问另一个函数的变量 也就是可以访问上一级的a也就是a=4,但是这个a不是指向顶级window 
}
}(function(a,b){
return a//这个是拿到4
}(4,8)))

 

 

demo(7)======>4