////////////decorator//////////
function aopFunc (target, key, descriptor) {
console.log('aopFunc')
} class foo { @aopFunc
bar () {
console.log('fooo')
} }
///////////////////////////// ///////////generator///////////
function* asyncFunc () {
var index = 0;
while (index < 3) {
yield index++
}
} var func = asyncFunc()
var result
while(result = func.next(), !result.done) {
console.log(result.value)
}
//////////////////////////////// /////////async/await/////////////
async function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
} (async function() {
console.log('Do some thing, ' + new Date())
await sleep(3000)
console.log('Do other things, ' + new Date())
})()
////////////////////////////// //////////async/await////////////
function timeout(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
} async function asyncPrint(value, ms) {
console.log('before hello world')
await timeout(ms);
console.log(value)
console.log('after hello world')
}
asyncPrint('hello world', 3000)
//////////////////////////////

decorator, async/await, generator的更多相关文章

  1. Generator function vs Async/Await

    Generator function vs Async/Await generator async /await refs xgqfrms 2012-2020 www.cnblogs.com 发布文章 ...

  2. Promise, Generator, async/await的渐进理解

    作为前端开发者的伙伴们,肯定对Promise,Generator,async/await非常熟悉不过了.Promise绝对是烂记于心,而async/await却让使大伙们感觉到爽(原来异步可以这么简单 ...

  3. async/await 与 generator、co 的对比

    之前写过一个分批预加载资源的插件,其实质便是串行执行异步,使用的方法是generator + promise -- 前几天写了一个爬虫,抓取页面的n个页面的音频资源,其也是串行执行异步,但是在使用的a ...

  4. JS异步编程 (2) - Promise、Generator、async/await

    JS异步编程 (2) - Promise.Generator.async/await 上篇文章我们讲了下JS异步编程的相关知识,比如什么是异步,为什么要使用异步编程以及在浏览器中JS如何实现异步的.最 ...

  5. Generator与async/await与Generator的模拟

    Generator 函数有多种理解角度.语法上,首先可以把它理解成,Generator 函数是一个状态机,封装了多个内部状态. 执行 Generator 函数会返回一个遍历器对象,也就是说,Gener ...

  6. ES6入门十一:Generator生成器、async+await、Promisify

    生成器的基本使用 生成器 + Promise async+await Promise化之Promisify工具方法 一.生成器的基本使用 在介绍生成器的使用之前,可以简单理解生成器实质上生成的就是一个 ...

  7. Promise、Generator,Async/await

    我们知道JavaScript是单线程语言,如果没有异步编程非得卡死. 以前,异步编程的方法有下面四种 回调函数 事件监听 发布/订阅 Promise对象 现在据说异步编程终极解决方案是——async/ ...

  8. 理解 async/await以及对Generator的优势

    async await 是用来解决异步的,async函数是Generator函数的语法糖使用关键字async来表示,在函数内部使用 await 来表示异步async函数返回一个 Promise 对象, ...

  9. ES6 Generator vs ES6 async/await

    ES6 Generator vs ES6 async/await next yield promise refs xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允 ...

随机推荐

  1. Code::Blocks + GDAL

    [root@server20 ~]# yum install cmake cmake-gui [root@server20 ~]# yum install cairo-devel libcurl-de ...

  2. selenium元素定位(Java)

    1.使用findElement方法定位元素   findElement()方法:当开始寻找符合指定条件的元素时,它将查询整个DOM,然后返回第一个找到的匹配元素.   By id:通过元素ID属性定位 ...

  3. 记录修改安卓5.0系统浏览器UI遇到的部分问题

    碎碎念 今年七月份本科毕业后入职一家会议平板公司,经过一个一个多月的咸鱼培训轮岗生活,接手了几个小任务,本次记录一下其中一个任务:修改安卓5.0系统浏览器UI.刚接到任务的时候,本以为是很简单的一个任 ...

  4. 【Java入门提高篇】Day21 Java容器类详解(四)ArrayList源码分析

    今天要介绍的是List接口中最常用的实现类——ArrayList,本篇的源码分析基于JDK8,如果有不一致的地方,可先切换到JDK8后再进行操作. 本篇的内容主要包括这几块: 1.源码结构介绍 2.源 ...

  5. (小技巧)Sql server查看sql语句的执行时间(转)

    转自CSDN: 在写数据库sql的时候,我们往往很关心该sql语句的执行效率,如下小技巧可以帮助程序员简单快速的得到某条或某几条sql的执行时间. declare @d datetime set @d ...

  6. office远程代码执行(CVE-2017-11882)

    office远程代码执行(CVE-2017-11882) 影响版本: MicrosoftOffice 2000 MicrosoftOffice 2003 MicrosoftOffice 2007 Se ...

  7. plsql备份表---只是表---不包含表数据

    写这个的同时还在备份,表的数据进度很慢,数据太大了. 用的工具是plsql 导出表:点击    tool工具  ---> export user object 导出用户目标  ----> ...

  8. echars关系图

    <!DOCTYPE html> <html> <head> <meta name="viewport" content="wid ...

  9. Vlc支持IE 360 低版本的Google浏览器

    VLC 插件代码: <object type='application/x-vlc-plugin' pluginspage="http://www.videolan.org/" ...

  10. Dos烧录脚本

    Dos命令之前更改的太简单,现在加入判断是否进入fasboot模式和判断Android镜像是否存在:代码已经尽量简化成这样,dos命令功能还是比较不好用的,用了一下午的时间... @echo off ...