博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用generator改写ajax
阅读量:4658 次
发布时间:2019-06-09

本文共 681 字,大约阅读时间需要 2 分钟。

function request(url) {    // this is where we're hiding the asynchronicity,    // away from the main code of our generator    // `it.next(..)` is the generator's iterator-resume    // call    makeAjaxCall( url, function(response){        it.next( response );    } );    // Note: nothing returned here!}function *main() {    var result1 = yield request( "http://some.url.1" );    var data = JSON.parse( result1 );    var result2 = yield request( "http://some.url.2?id=" + data.id );    var resp = JSON.parse( result2 );    console.log( "The value you asked for: " + resp.value );}var it = main();it.next(); // get it all started

 

转载于:https://www.cnblogs.com/panyujun/p/10348855.html

你可能感兴趣的文章
ef linq 中判断实体中是否包含某集合
查看>>
章三 链表
查看>>
Solution for Concurrent number of AOS' for this application exceeds the licensed number
查看>>
CSE 3100 Systems Programming
查看>>
IntelliJ IDEA 的Project structure说明
查看>>
Java Security(JCE基本概念)
查看>>
创建 PSO
查看>>
JasperReport报表设计4
查看>>
项目活动定义 概述
查看>>
团队冲刺04
查看>>
我的Python分析成长之路8
查看>>
泛型在三层中的应用
查看>>
SharePoint2010 -- 管理配置文件同步
查看>>
.Net MVC3中取得当前区域的名字(Area name)
查看>>
获得屏幕像素以及像素密度
查看>>
int与string转换
查看>>
adb命令 判断锁屏
查看>>
推荐一个MacOS苹果电脑系统解压缩软件
查看>>
1035等差数列末项计算
查看>>
CDMA鉴权
查看>>