当前位置:网站首页>es6 Generator函数的使用
es6 Generator函数的使用
2022-04-22 17:51:00 【你的美,让我痴迷】
function* foo(){
yield 1;
yield 2;
yield 3;
}
var f = foo();
console.log(f.next());//{ value: 1, done: false }
console.log(f.return("foo"));//
function* callee() {
console.log('callee: ' + (yield));
}
function* caller() {
while (true) {
yield* callee();
}
}
const callerObj = caller();
console.log(callerObj.next());
function* objectEntries(obj) {
const propKeys = Reflect.ownKeys(obj);
for (const propKey of propKeys) {
yield [propKey, obj[propKey]];
}
}
const jane = {
first: 'Jane', last: 'Doe' };
for (const [key,value] of objectEntries(jane)) {
console.log(`${
key}: ${
value}`);
}
打印结果:

版权声明
本文为[你的美,让我痴迷]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45932157/article/details/124349811
边栏推荐
- National information exchange model (NIEM) operation manual
- 软考高项笔记 | PERT 三点估算
- 如何快速接入直播服务 七牛云企业直播解决方案来了
- 你知道你的手机上有多少传感器吗?
- Cisp-pte SQL injection advanced level bypass bypass skills
- Notes on soft test high items | information system life cycle
- 软考高项笔记 | 信息化的五个层次
- Notes on soft test high items | contents of detailed feasibility study
- 电子书产品日趋丰富,科大讯飞智能办公本仍是理想之选
- L1-002 打印沙漏 (20 分)
猜你喜欢

软考高项笔记 | 项目管理知识体系构成

OPLG:新一代云原生可观测最佳实践

软考高项笔记 | 项目建议书的内容

March 2022 - true questions and analysis of C language (Level 2) in the youth grade examination of the Electronic Society

S7-1500 specific methods and steps of data exchange between CPU and OPC UA server through OPC UA client

Daily practice - day 1 -3.18
Android--sqlite

Notes on soft test high items | contents of detailed feasibility study

tbb concurrent_multiset/concurrent_set unsafe_erase() 崩溃

【C语言进阶篇】一篇文章带你认清结构、枚举和联合
随机推荐
Soft test high-level notes | tools and techniques for collecting needs
DOM的综合应用的例子--点击加一和减一
常见的测试技术
Unable to translate SQLException with Error code ‘0‘, will now try the fallback translator
优麒麟 22.04 LTS 版本正式发布 | UKUI 3.1开启全新体验!
dpdk从环形队列ring获取解析数据包,并使用hashtable统计
一文了解进程及其通信方法
微软测试人员简述
How does the usdd anchored to the US dollar lead the transformation of digital currency
阿里云容器&服务网格产品技术动态(202203)
How can the AVI file exported from PR be read by ImageJ?
Design the test paper storage scheme of ten million students management system
Sunyuchen announced the launch of usdd to promote financial freedom
Get rid of the "small workshop" of AI production: how to build a cloud native AI platform based on kubernetes
Notes on soft test high items | contents of feasibility study
find lower_bound upper_bound
Servlet 的继承关系
软考高项笔记 | 运维服务分类
idea设置services窗口显示树状服务
Audio, video and IM, Bing brother summary