Files
charlie 877acb5a8f feat: Add JavaScript core exercises and solutions
- Implemented exercises for array high-order methods, memory and execution, switch statements, and final review.
- Added starter and answer files for each exercise to facilitate learning.
- Created a runner HTML file to execute JavaScript code and display console outputs.
- Updated README files to include exercise objectives, tasks, and usage instructions.
2026-03-13 11:09:19 +08:00

29 lines
747 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 练习 9闭包入门
## 目标
初步理解闭包为什么能把外层变量“记住”。
## 你要练什么
- 外层变量
- 内层函数
- 闭包的基本效果
- 多个闭包实例互不影响
## 任务
请完成一个“计数器工厂”脚本,要求:
- 写一个 `createCounter` 函数
- 在函数内部定义 `count`
- 返回一个内部函数
- 每次调用内部函数时,`count` 都加 1
- 创建两个不同的计数器
- 观察为什么它们各自记住了自己的 `count`
## 文件
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/03-javascript-core/09-scope-and-closure/starter.js)
- [answer.js](/Users/lijiaqing/home/wwwroot/front-end-example/03-javascript-core/09-scope-and-closure/answer.js)