deferred object

Download Deferred object

Post on 19-Jun-2015

1.282 views

Category:

Software

1 download

Embed Size (px)

DESCRIPTION

Event Loop and Deverred Object

TRANSCRIPT

  • 1. Deferred Object ## javarouka@gmail.com

2. JavaScript JavaScript . . // . var i = 0, beerCargo = document.getElementById( beerCargo); while (Number.MAX_VALUE > i) { beerCargo.innerHTML += drink + i + beer!
; i++; } 3. 4. Queue 1. . 2. FIFO Queue . 3. Queue , . 4. 5. ? 6. . 7. , JavaScript ? 8. Callback 9. ? callbackhell.com 10. . . . 11. ? , then . ? 12. Promise/A http://wiki.commonjs.org/wiki/Promises/A 13. Promise/A - , . Queue Event Loop Queue . 14. jQuery Deferred Object http://api.jquery.com/category/deferred-object/ AngularJS $q https://docs.angularjs.org/api/ng/service/$q 15. jQuery Deferred Object 16. jQuery Ajax $.ajax({ url: "test.html", context: document.body, success: function() { $( this ).addClass( "done" ); }, error: function() { alert( "opps!!!!" ); } ); 17. Deferred! var promise = $.ajax({ url: "test.html", context: document.body }); promise.done(function() { $( this ).addClass( "done" ); }); promise.fail(function() { alert( "opps!!!!" ); }); 18. . Promise . . . HTML , , ... 19. Multi Complete API, API, API . ? 20. $.when var userPromise = $.get("/user"), orderPromise = $.get("/order"), productPromise = $.get("/product"); $.when(userPromise, orderPromise, productPromise) .done(function() { ... }) .fail(function() { ... }); 21. https://github.com/javarouka/javarouka.github. com/blob/master/javascript/deferred.html http://javarouka.github.io/javascript/deferred.html