当前位置:网站首页>闭包问题
闭包问题
2022-06-27 07:36:00 【算法与编程之美】
问题描述
闭包就是一个可以访问其他作用域的矢量,这样的一个函数称为闭包。
2.算法描述
定义一个函数outer,当outer函数第一次中执行时,声明一个局部变量a=100,以及声明了第一个函数inner函数的声明部分并且把inner函数声明部分返回,当再次执行的时候,在自身的作用域中没有变量a,会沿着作用域链向上查询,而且每次在基础上加上10。
3.实验讨论与结果
找出其中的内在逻辑,并写出过程,带入值,输出结果。
<!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> |
四.结语
闭包问题主要是了解这个逻辑中的主次关系,在大的框架下再进行小的各层次的运算。不同的声明部分决定了不同的结果,再次进行一个新的计算时。
边栏推荐
猜你喜欢
File and multipartfile overview
「短视频」临夏消防救援支队开展消防安全培训授课
Gérer 1000 serveurs par personne? Cet outil d'automatisation o & M doit être maîtrisé
js例题打印1-100之间所有7的倍数的个数及总和
JS, and output from small to large
一個人管理1000臺服務器?這款自動化運維工具一定要掌握
MySQL
js中判断奇偶的函数,求圆面积的函数
One person manages 1000 servers? This automatic operation and maintenance tool must be mastered
在线文本数字识别列表求和工具
随机推荐
使用 Blackbox Exporter 测试网络连通性
语音合成:Tacotron详解【端到端语音合成模型】【与传统语音合成相比,它没有复杂的语音学和声学特征模块,而是仅用<文本序列,语音声谱>配对数据集对神经网络进行训练,因此简化了很多流程】
R 语言Analyzing wine data
基础知识 | js基础
攻防演习防御体系构建之第二篇之应对攻击的常用策略
Rust Async: smol源码分析-Executor篇
Apifox learning
guava 定时任务
postgreSQL在windows系统遇到权限否认(permission denied)
Solve the problem of win10 wsl2 IP change
JS uses the while cycle to calculate how many years it will take to grow from 1000 yuan to 5000 yuan if the interest rate for many years of investment is 5%
JS to determine whether the result is qualified, the range is 0-100, otherwise re-enter
碎煤机crusher
通过uview让tabbar根据权限显示相应数量的tabbar
File and multipartfile overview
apifox学习
2022 cisp-pte (II) SQL injection
数据库系统工程师对口专业有哪些?
JS example print the number and sum of multiples of all 7 between 1-100
Goodbye, agile Scrum