当前位置:网站首页>闭包实现迭代器效果
闭包实现迭代器效果
2022-07-01 09:13:00 【su27_0101】
迭代器
反复调用一个函数 会返回不同的值 但这些值有具有一定关联 比如是数组内顺序存储的数
- 数组迭代器
var arr = [1,2,3,4,5];
var next = (function(){
var index = 0;
return function(){
if(index>=arr.length){
throw new Error("无法继续迭代");
}
return arr[index++];
}
})()
next();//1
1
next();
2
next();
3
next();
4
next();
5
next();
VM871:6 Uncaught Error: 无法继续迭代
at <anonymous>:6:9
at <anonymous>:1:1
边栏推荐
- 通过 代码实例 理解 浅复制 与 深复制
- laravel postman 提交表单出现419错误。2020年7月6日记。
- Yidian Yidong helps enterprises to efficiently manage equipment and improve equipment utilization
- Shell script - special variables: shell $, $*, [email protected], $$$
- [ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + MQ Series + nodejs local service + MySQL storage
- jeecg 重启报40001
- 易点易动助力企业设备高效管理,提升设备利用率
- 【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + DS18B20温度传感器 +NodeJs本地服务+ MySQL数据库
- 【pytorch】softmax函数
- Summary of reptile knowledge points
猜你喜欢

dsPIC30F6014a LCD 方块显示

Learning practice: comprehensive application of cycle and branch structure (II)

jeecg 重启报40001

How to solve the problem of fixed assets management and inventory?

Why is the Ltd independent station a Web3.0 website!

樹結構---二叉樹2非遞歸遍曆

FAQ | FAQ for building applications for large screen devices

【电赛训练】红外光通信装置 2013年电赛真题

Jeecg restart alarm 40001

Tree structure -- binary tree 2 non recursive traversal
随机推荐
How to realize the usage of connecting multiple databases in idel
tensorrt yolov5_ trt. Py comments
2.4 激活函数
How to manage fixed assets efficiently in one stop?
Differences among tasks, threads and processes
FAQ | FAQ for building applications for large screen devices
I use flask to write the website "one"
钓鱼识别app
Shell script case in and regular expressions
如何高效拉齐团队认知
【pytorch】softmax函数
Record a redis timeout
Simple load balancing with Nacos
Shell script -select in loop
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + MQ Series + nodejs local service + MySQL storage
Shell脚本-特殊变量:Shell $#、$*、[email protected]、$?、$$
nacos簡易實現負載均衡
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + MQ系列 + NodeJs本地服务 + MySql存储
3D打印Arduino 四轴飞行器
小鸟识别APP