📖 什么是闭包?闭包(Closure)是JavaScript中一个重要且强大的概念。简单来说,闭包就是一个函数能够访问其外部作用域中变量的能力,即使在外部函数执行完毕后。
123456789101112131415function outerFunction(x) { // 外部函数的变量 let outerVariable = x; // 内部函数 function innerFunction(y) { // 访问外部函数的变量 console.log(outerVariable + y); } return innerFunction;}const myClosure = outerFunction(10);myClosure(5); // 输出: 15
🔍 闭包的工作原理词法作用域JavaScript使用词法作用域,这意味着函数的作用域在定义时就确定了,而不是在调用时。
1234567891011121314let globalVar = "全局变量";function oute ...
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
Quick StartCreate a new post1$ hexo new "My New Post"
More info: Writing
Run server1$ hexo server
More info: Server
Generate static files1$ hexo generate
More info: Generating
Deploy to remote sites1$ hexo deploy
More info: Deployment
