1 window.addEventListener('load', function(){2 test2();3 }, true);4 5 6 /**7 * Ajax8 */9 function Ajax(manager) {10 11 this._manager = manager;12 this._id = 0;13 this._xhr = null;14 }15 16 Ajax.prototype.send = function() {17 this._manager.push(this);18 };19 20 Ajax.prototype.abort = function() {21 22 }23 24 /**25 * Ajax Manager26 */27 AjaxMan = (function() {28 29 var queue = [];30 var id_generator = 0;31 32 return {33 newAjax:function() {34 var new_ajax = new Ajax(this);35 new_ajax._id = id_generator; id_generator++;36 return new_ajax;37 },38 push:function(ajax) {39 if (!this.isQueued(ajax)) {40 logger.log('is not queued, do push');41 queue.push(ajax);42 } else {43 logger.log('IS queued');44 }45 },46 isQueued:function(ajax) {47 return queue.indexOf(ajax) > -1;48 }49 50 };51 52 })();53 54 55 /**56 * Create 10 ajax57 */58 function test1() {59 60 var index = {};61 62 logger.show();63 64 for (var i = 0; i<10; i++) {65 logger.log(AjaxMan.newAjax());66 }67 68 }69 70 /**71 * Send 10 ajax72 */73 function test2() {74 75 var index = {};76 77 logger.show();78 79 var ajax = AjaxMan.newAjax();80 81 for (var i = 0; i<10; i++) {82 ajax.send();83 }84 85 }86 87 88
Este ShareCode tiene versiones:
- Ajax Manager ... (24/04/2013)
- Ajax Manager ... (24/04/2013)
- Ajax Manager ... (24/04/2013)
- Ajax Manager ... (24/04/2013)
Enlace
El enlace para compartir es: