当前位置:网站首页>Closure problem
Closure problem
2022-06-27 07:43:00 【Beauty of algorithm and programming】
Problem description
A closure is a vector that can access other scopes , Such a function is called a closure .
2. Algorithm description
Define a function outer, When outer When the function is first executed in , Declare a local variable a=100, And declare the first function inner Function and put inner The function declaration part returns , When executed again , There are no variables in its scope a, Query up the scope chain , And every time I add 10.
3. Experimental discussion and results
Find out the internal logic , And write the process , Bring in value , Output results .
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> </body> </html> <script type="text/javascript"> function outer (){ var a=100; function inner(){ a+=10 console.log(a); } return inner; } var result =outer(); result(); result(); var result1=outer(); result1(); </script> |
Four . Conclusion
The closure problem is mainly to understand the primary and secondary relationships in this logic , In the large framework, we can carry out small operations at all levels . Different declaration parts determine different results , When a new calculation is performed again .
边栏推荐
- JDBC reads MySQL data list
- File 与 MultipartFile概述
- R language calculates Spearman correlation coefficient in parallel to speed up the construction of co occurrence network
- js求所有水仙花数
- JS use the switch statement to output the corresponding English day of the week according to 1-7
- 闭包问题
- 攻防演习防御体系构建之第二篇之应对攻击的常用策略
- (resolved) NPM suddenly reports an error cannot find module 'd:\program files\nodejs\node_ modules\npm\bin\npm-cli. js‘
- Yarn create vite reports an error 'd:\program' which is neither an internal or external command nor a runnable program or batch file
- What are the specialties of database system engineers?
猜你喜欢
再见了,敏捷Scrum
【批处理DOS-CMD命令-汇总和小结】-将文件夹映射成虚拟磁盘——subst
js用switch输出成绩是否合格
[Kevin's third play in a row] is rust really slower than C? Further analyze queen micro assessment
Speech signal feature extraction process: input speech signal - framing, pre emphasis, windowing, fft- > STFT spectrum (including amplitude and phase) - square the complex number - > amplitude spectru
二叉树结构以及堆结构基础
How to view program running time (timer) in JS
js中判断成绩是否合格,范围在0-100,否则重新输入
大厂工作十年,年薪40万突然被裁员,公司想抛弃你,一分情面都不会留
What is a magnetic separator?
随机推荐
Cookie加密6
语音信号处理-概念(一):时谱图(横轴:时间;纵轴:幅值)、频谱图(横轴:频率;纵轴:幅值)--傅里叶变换-->时频谱图【横轴:时间;纵轴:频率;颜色深浅:幅值】
认识O(NlogN)的排序
一个人管理1000台服务器?这款自动化运维工具一定要掌握
Idea方法模板
window右键管理
无论LCD和OLED显示技术有多好,都无法替代这个古老的显示数码管
JS performance reward and punishment examples
(笔记)Anaconda-Navigator闪退解决方法
js输出1-100之间所有的质数并求总个数
js判断用户输入的数是否为质数(多种方法)
Bean copy details
c#的初步认识
R 语言并行计算 spearman 相关系数,加快共现网络(co- occurrence network)构建速度
Guava tutorial collect some cases and write Google tool classes slowly
R 语言Analyzing wine data
JS use switch to output whether the result is qualified
Origin of forward slash and backslash
磁选机是什么?
Cookie encryption 6