function foo(){ var a=20 function bar(){ a=a*2; return a } return bar //返回一个内嵌函数 } var baz = foo() //函数在外面调用,能访问的a变量, 函数运行在定义他们的作用域中 //bar定义在foo中,就能访问foo定义的所有变量 console.log('111',baz) console.log('222',baz()) //40 console.log('222',baz()) //80 console.log('222',baz()) //160 var baz2 = foo() console.log('222',baz2()) //40