当前位置:网站首页>闭包实现迭代器效果
闭包实现迭代器效果
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
边栏推荐
- The fixed assets management system enables enterprises to dynamically master assets
- Pain points and solutions of equipment management in large factories
- Mysql8.0 learning record 17 -create table
- [pytorch learning] torch device
- How to solve the problem of fixed assets management and inventory?
- Niuke monthly race 22- collect pieces of paper
- Full mark standard for sports items in the high school entrance examination (Shenzhen, Anhui and Hubei)
- 易点易动助力企业设备高效管理,提升设备利用率
- Serialization, listening, custom annotation
- 【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + DHT11 +NodeJs本地服务+ MySQL数据库
猜你喜欢
How to manage fixed assets well? Easy to point and move to provide intelligent solutions
Jetson Nano 安装TensorFlow GPU及问题解决
Phishing identification app
NoSQL数据库的安装和使用
安装Oracle EE
Principles of Microcomputer - internal and external structure of microprocessor
Pain points and solutions of equipment management in large factories
2.4 激活函数
FAQ | FAQ for building applications for large screen devices
猿人学第20题(题目会不定时更新)
随机推荐
Learning practice: comprehensive application of cycle and branch structure (II)
jeecg 重启报40001
Structure de l'arbre - - - arbre binaire 2 traversée non récursive
JCL and slf4j
Full mark standard for sports items in the high school entrance examination (Shenzhen, Anhui and Hubei)
How to solve the problem of fixed assets management and inventory?
2.4 activation function
Jetson Nano 安装TensorFlow GPU及问题解决
Pain points and solutions of equipment management in large factories
Key points of NFT supervision and overseas policies
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + MQ系列 + NodeJs本地服务 + MySql存储
nacos服务配置和持久化配置
Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)
LogBack
Shell script - special variables: shell $, $*, [email protected], $$$
Redis——Lettuce连接redis集群
Shell script -while loop explanation
Niuke monthly race 22- collect pieces of paper
[pytorch] softmax function
Daily office consumables management solution