当前位置:网站首页>闭包实现迭代器效果
闭包实现迭代器效果
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
边栏推荐
- Football and basketball game score live broadcast platform source code /app development and construction project
- Shell script -read command: read data entered from the keyboard
- Principles of Microcomputer - Introduction
- Shell script -while loop explanation
- 【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的WS2812灯控系统
- 2.3 【pytorch】数据预处理 torchvision.datasets.ImageFolder
- Graduation season, I want to tell you
- Shell script -for loop and for int loop
- 【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的温湿度监控系统
- Pain points and solutions of fixed assets management of group companies
猜你喜欢

Football and basketball game score live broadcast platform source code /app development and construction project

安装Oracle EE

nacos簡易實現負載均衡

FAQ | FAQ for building applications for large screen devices

【pytorch】softmax函数
![[pytorch] 2.4 convolution function nn conv2d](/img/eb/382a00af5f88d5954f10ea76343d6e.png)
[pytorch] 2.4 convolution function nn conv2d

Jetson nano installs tensorflow GPU and problem solving

Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)

TV size and viewing distance

Ranking list of domestic databases in February, 2022: oceanbase regained the "three consecutive increases", and gaussdb is expected to achieve the largest increase this month
随机推荐
Naoqi robot summary 28
Key points of NFT supervision and overseas policies
[ESP nanny level tutorial] crazy completion chapter - Case: ws2812 light control system based on Alibaba cloud, applet and Arduino
小鸟识别APP
FAQ | FAQ for building applications for large screen devices
Shell script -for loop and for int loop
Youqitong PE toolbox [vip] v3.7.2022.0106 official January 22 Edition
Preparing for the Blue Bridge Cup -- bit operation
2.4 activation function
树结构---二叉树1
Shell script - special variables: shell $, $*, [email protected], $$$
Shell script -read command: read data entered from the keyboard
Jeecg restart alarm 40001
Structure de l'arbre - - - arbre binaire 2 traversée non récursive
Pain points and solutions of equipment management in large factories
Record a redis timeout
tensorrt yolov5_ trt. Py comments
Embedded Engineer Interview Question 3 Hardware
毕业季,我想对你说
Redis -- lattice connects to redis cluster