当前位置:网站首页>闭包实现迭代器效果
闭包实现迭代器效果
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
边栏推荐
- Personal decoration notes
- [ESP nanny level tutorial] crazy completion chapter - Case: temperature and humidity monitoring system based on Alibaba cloud, applet and Arduino
- Learning practice: comprehensive application of cycle and branch structure (II)
- 2.2 【pytorch】torchvision.transforms
- Niuke monthly race 22- collect pieces of paper
- Shell script echo command escape character
- Which method is good for the management of fixed assets of small and medium-sized enterprises?
- Pain points and solutions of equipment management in large factories
- FAQ | FAQ for building applications for large screen devices
- 2.3 [pytorch] data preprocessing torchvision datasets. ImageFolder
猜你喜欢

Tree structure -- binary tree 2 non recursive traversal

Principles of Microcomputer - internal and external structure of microprocessor

足球篮球体育比赛比分直播平台源码/app开发建设项目

Understanding and implementation of AVL tree

2.3 【kaggle数据集 - dog breed 举例】数据预处理、重写Dataset、DataLoader读取数据

Which method is good for the management of fixed assets of small and medium-sized enterprises?

【pytorch】2.4 卷积函数 nn.conv2d

3D打印Arduino 四轴飞行器

I use flask to write the website "one"

nacos简易实现负载均衡
随机推荐
樹結構---二叉樹2非遞歸遍曆
Structure de l'arbre - - - arbre binaire 2 traversée non récursive
Jeecg restart alarm 40001
Shell脚本-read命令:读取从键盘输入的数据
How to effectively align team cognition
Key points of NFT supervision and overseas policies
SDN_ Simple summary
【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的温湿度监控系统
毕业季,我想对你说
How to manage fixed assets efficiently in one stop?
Input标签的type设置为number,去掉上下箭头
dsPIC30F6014a LCD 方块显示
Shell script -while loop explanation
Installation and use of NoSQL database
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + DS18B20温度传感器 +NodeJs本地服务+ MySQL数据库
I use flask to write the website "one"
Redis -- lattice connects to redis cluster
Simple load balancing with Nacos
JCL and slf4j
Daily practice of C language - day 80: currency change