使用闭包保存变量,下次调用不会被销毁(垃圾回收)
<!DOCTYPE html> <html> <head> <meta charset=utf-8> </head> <body> <script type="text/javascript"> const closure = () => { // 补全代码 let conut = 1 return function() {return conut++} } </script> </body> </html>