JavaScript异步编程学习

来源:互联网 发布:深圳龙岗ug编程培训 编辑:程序博客网 时间:2024/06/07 23:01
一 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()同步并行任务 
Java代码  收藏代码
  1. var servdata = {};  
  2.  var promiseOne = $.ajax({ url: '../1.json' });  
  3.  var promiseTwo = $.ajax({ url: '../2.json' });    
  4.  promiseOne.done(function (result) {  
  5.     console.log('PromiseOne Done');  
  6.     servdata['1']=result;  
  7.  });  
  8.  promiseTwo.done(function (result) {  
  9.     console.log('PromiseTwo Done');  
  10.     servdata['2']=result;  
  11.  });        
  12.  $.when(promiseOne,promiseTwo)  
  13.  .done(function () {  
  14.     console.log('promiseOne and promiseTwo are done');  
  15.     //数据已准备好了  
  16.  }).fail(function () {  
  17.     console.log('One of our promises failed');  
  18.  });  

5、管道连接未来(pipe,http://www.css88.com/jqapi-1.9/deferred.pipe/) 
Java代码  收藏代码
  1.  var request = $.ajax( url, { dataType: "json" } ),  
  2. chained = request.pipe(function( data ) {  
  3.   return $.ajax( url2, { data: { user: data.userId } } );  
  4. });   
  5. chained.done(function( data ) {  
  6.   // data retrieved from url2 as provided by the first request  
  7. });  


四 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) 
Java代码  收藏代码
  1. yepnope([{   
  2. test : /* boolean(ish) - 你要检查真伪的表达式 */,   
  3. yep : /* array (of strings) | string - test为true时加载这项 */,   
  4. nope : /* array (of strings) | string - test为false时加载这项 */,   
  5. both : /* array (of strings) | string - 什么情况下都加载 */,   
  6. load : /* array (of strings) | string - 什么情况下都加载 */,   
  7. callback : /* function ( testResult, key ) | object { key : fn } 当某个url加载成功时执行相应的方法 */,   
  8. complete : /* function 都加载完成了执行这个方法 */   
  9. }, ... ]);   

7、Require.js/AMD智能加载 
0 0
原创粉丝点击