JavaScript异步编程学习

一 JavaScript学习资源
1、Reg Braithwaite Captain Obvious on Javascript ( http://raganwald.com/2014/05/30/repost-captain-obvious.html
2、交互式教程网站 https://www.codecademy.com/
3、交互式Jquery空中学堂 https://www.codeschool.com
4、JavaScript正式介绍 http://.github.io/JavaScript-Garden/
6、求助网站 https://developer.mozilla.orgeloquentjavascript.net/
5、JavaScript初学者 http://bonsaiden
7、开发者社区 http://stackoverflow.com/
8、腾讯公司IMWeb团队 https://github.com/imweb
9 jquery文档: http://www.css88.com/jqapi-1.9/

二  PubSub(发布订阅)模式
1、 http://imweb.io/topic/565dde4d4c460c2f5385b955
2、 http://www.itxueyuan.org/view/6931.html
3、在jQuery1.7 中将它们抽象为$.Callbacks

三 Promise & Deferred对象(合并多异步回调及结果),可用它代替回调
1、Promises是一种令代码异步行为更加优雅的抽象,可能是下一个编程范式,一个Promise即表示任务结果,无论该任务是否完成。
2、 http://www.csdn.net/article/2013-08-12/2816527-JavaScript-Promise
3、 http://www.cnblogs.com/my_front_research/p/3228333.html
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, http://www.css88.com/jqapi-1.9/deferred.pipe/
 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的工具包,代替库: https://github.ocm/crationix/step
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
示例:( https://www.uedsc.com/yepnope-js.html
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智能加载






猜你喜欢

转载自liuzidong.iteye.com/blog/2305947