闭包:一个函数中有另一个函数或对象。里面的函数或对象可以调用外面的函数定义的变量或数据。此时形成闭包。 闭包的作用:缓存数据,延长作用域链。(同时这也是缺点,因为这导致函数中的变量不能及时释放)
function f1(){ var num=10; return function(){ console.log(num); //10 ,这里函数可以调用其外部的函数f1定义的num,此时形成闭包。 } } f1();