当前位置:网站首页>闭包实现迭代器效果
闭包实现迭代器效果
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
边栏推荐
- Jeecg restart alarm 40001
- Shell script -read command: read data entered from the keyboard
- [ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + MQ Series + nodejs local service + MySQL storage
- Which method is good for the management of fixed assets of small and medium-sized enterprises?
- Shell脚本-while循环详解
- laravel postman 提交表单出现419错误。2020年7月6日记。
- Structure de l'arbre - - - arbre binaire 2 traversée non récursive
- Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)
- Bird recognition app
- Mysql8.0 learning record 17 -create table
猜你喜欢

NiO zero copy

Preparing for the Blue Bridge Cup -- bit operation

Implementation and application of queue

Installing Oracle EE

Personal decoration notes

【pytorch】2.4 卷积函数 nn.conv2d

Pain points and solutions of equipment management in large factories
![2.3 [kaggle dataset - dog feed example] data preprocessing, rewriting dataset, dataloader reading data](/img/6e/d8ef618127ac492f5142f7b600266d.png)
2.3 [kaggle dataset - dog feed example] data preprocessing, rewriting dataset, dataloader reading data

MySQL optimization

【pytorch】nn.CrossEntropyLoss() 与 nn.NLLLoss()
随机推荐
Redis——Lettuce连接redis集群
Class loading
2.3 [pytorch] data preprocessing torchvision datasets. ImageFolder
I use flask to write the website "one"
FAQ | FAQ for building applications for large screen devices
Interrupt sharing variables with other functions and protection of critical resources
2.4 激活函数
It technology ebook collection
Shell script case in and regular expressions
Niuke monthly race 22- collect pieces of paper
Differences among tasks, threads and processes
Learning practice: comprehensive application of cycle and branch structure (II)
Shell脚本-case in语句
Preparing for the Blue Bridge Cup -- bit operation
tensorrt yolov5_ trt. Py comments
Embedded Engineer Interview Question 3 Hardware
How to launch circle of friends marketing and wechat group activities
[pytorch learning] torch device
SDN_ Simple summary
Win7 pyinstaller reports an error DLL load failed while importing after packaging exe_ Socket: parameter error