JavaScript异步编程学习
一 JavaScript学习资源
1、Reg Braithwaite Captain Obvious on Javascript ([url]http://raganwald.com/2014/05/30/repost-captain-obvious.html[/url])
2、交互式教程网站 [url]https://www.codecademy.com/[/url]
3、交互式Jquery空中学堂 [url]https://www.codeschool.com[/url]
4、JavaScript正式介绍 [url]http://.github.io/JavaScript-Garden/[/url]
6、求助网站 [url]https://developer.mozilla.orgeloquentjavascript.net/[/url]
5、JavaScript初学者 [url]http://bonsaiden[/url]
7、开发者社区 [url]http://stackoverflow.com/[/url]
8、腾讯公司IMWeb团队 [url]https://github.com/imweb[/url]
9 jquery文档:[url]http://www.css88.com/jqapi-1.9/[/url]
二 PubSub(发布订阅)模式
1、[url]http://imweb.io/topic/565dde4d4c460c2f5385b955[/url]
2、[url]http://www.itxueyuan.org/view/6931.html[/url]
3、在jQuery1.7 中将它们抽象为$.Callbacks
三 Promise & Deferred对象(合并多异步回调及结果),可用它代替回调
1、Promises是一种令代码异步行为更加优雅的抽象,可能是下一个编程范式,一个Promise即表示任务结果,无论该任务是否完成。
2、[url]http://www.csdn.net/article/2013-08-12/2816527-JavaScript-Promise[/url]
3、[url]http://www.cnblogs.com/my_front_research/p/3228333.html[/url]
4、使用$.when()同步并行任务
5、管道连接未来(pipe,[url]http://www.css88.com/jqapi-1.9/deferred.pipe/[/url])
四 Async.js工作流控制(处理异步js的工具包,代替库:[url]https://github.ocm/crationix/step[/url])
1、异步工作流的次序问题
2、异步的数据收集方式
3、任务组织技术
4、异步工作流的的动态排除技术
5、step的工作流控制方式
五 worker对象的多线程技术
1、网页版的worker对象,它是H5的一部分
六 异步的脚本加载
1、H5的async/defer作用
2、defer是等待文档加载有序排除场景
3、async无序运行
4、推荐使用:defer
5、向Dom插入script标签
6、yepnope.js(http://yepnopejs.com/)是一个能够根据输入条件来选择性异步加载资源文件的js脚本,可以在页面上仅加载用户需要的js/css
示例:([url]https://www.uedsc.com/yepnope-js.html[/url])
7、Require.js/AMD智能加载
1、Reg Braithwaite Captain Obvious on Javascript ([url]http://raganwald.com/2014/05/30/repost-captain-obvious.html[/url])
2、交互式教程网站 [url]https://www.codecademy.com/[/url]
3、交互式Jquery空中学堂 [url]https://www.codeschool.com[/url]
4、JavaScript正式介绍 [url]http://.github.io/JavaScript-Garden/[/url]
6、求助网站 [url]https://developer.mozilla.orgeloquentjavascript.net/[/url]
5、JavaScript初学者 [url]http://bonsaiden[/url]
7、开发者社区 [url]http://stackoverflow.com/[/url]
8、腾讯公司IMWeb团队 [url]https://github.com/imweb[/url]
9 jquery文档:[url]http://www.css88.com/jqapi-1.9/[/url]
二 PubSub(发布订阅)模式
1、[url]http://imweb.io/topic/565dde4d4c460c2f5385b955[/url]
2、[url]http://www.itxueyuan.org/view/6931.html[/url]
3、在jQuery1.7 中将它们抽象为$.Callbacks
三 Promise & Deferred对象(合并多异步回调及结果),可用它代替回调
1、Promises是一种令代码异步行为更加优雅的抽象,可能是下一个编程范式,一个Promise即表示任务结果,无论该任务是否完成。
2、[url]http://www.csdn.net/article/2013-08-12/2816527-JavaScript-Promise[/url]
3、[url]http://www.cnblogs.com/my_front_research/p/3228333.html[/url]
4、使用$.when()同步并行任务
var servdata = {};
var promiseOne = $.ajax({ url: '../1.json' });
var promiseTwo = $.ajax({ url: '../2.json' });
promiseOne.done(function (result) {
console.log('PromiseOne Done');
servdata['1']=result;
});
promiseTwo.done(function (result) {
console.log('PromiseTwo Done');
servdata['2']=result;
});
$.when(promiseOne,promiseTwo)
.done(function () {
console.log('promiseOne and promiseTwo are done');
//数据已准备好了
}).fail(function () {
console.log('One of our promises failed');
});
5、管道连接未来(pipe,[url]http://www.css88.com/jqapi-1.9/deferred.pipe/[/url])
var request = $.ajax( url, { dataType: "json" } ),
chained = request.pipe(function( data ) {
return $.ajax( url2, { data: { user: data.userId } } );
});
chained.done(function( data ) {
// data retrieved from url2 as provided by the first request
});
四 Async.js工作流控制(处理异步js的工具包,代替库:[url]https://github.ocm/crationix/step[/url])
1、异步工作流的次序问题
2、异步的数据收集方式
3、任务组织技术
4、异步工作流的的动态排除技术
5、step的工作流控制方式
五 worker对象的多线程技术
1、网页版的worker对象,它是H5的一部分
六 异步的脚本加载
1、H5的async/defer作用
2、defer是等待文档加载有序排除场景
3、async无序运行
4、推荐使用:defer
5、向Dom插入script标签
6、yepnope.js(http://yepnopejs.com/)是一个能够根据输入条件来选择性异步加载资源文件的js脚本,可以在页面上仅加载用户需要的js/css
示例:([url]https://www.uedsc.com/yepnope-js.html[/url])
yepnope([{
test : /* boolean(ish) - 你要检查真伪的表达式 */,
yep : /* array (of strings) | string - test为true时加载这项 */,
nope : /* array (of strings) | string - test为false时加载这项 */,
both : /* array (of strings) | string - 什么情况下都加载 */,
load : /* array (of strings) | string - 什么情况下都加载 */,
callback : /* function ( testResult, key ) | object { key : fn } 当某个url加载成功时执行相应的方法 */,
complete : /* function 都加载完成了执行这个方法 */
}, ... ]);
7、Require.js/AMD智能加载