The first result will log undefined for the supposed deferred whereas the second will return the deferred. This is due to the resolution of the callback occurring before the assignment of the referenced variable happens. Note to reproduce this multiple times in console, a new variable will need to be used, otherwise it will seemingly pass because the deferred object already exists.
Created
April 27, 2016 16:15
-
-
Save naganowl/5c5b57ee2bc847e8966c37e36801fbc6 to your computer and use it in GitHub Desktop.
Chaining method calls that are async with assignment can lead to problems
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = $.Deferred.resolve(); | |
window.foob = $.when(x).done(function(){console.log(1, window.foob)}); console.log('asdf'); | |
window.fooba = $.when(x); fooba.done(function(){console.log(1, window.fooba)}); console.log('asdf'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment