Created
August 18, 2014 02:57
-
-
Save DannyJoris/6f37a067bb0071143ca9 to your computer and use it in GitHub Desktop.
// source http://jsbin.com/yepude/1
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
.box { | |
display: none; | |
width: 100px; | |
height: 100px; | |
border: 1px solid hotpink; | |
background: white; | |
margin: 10px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="box box1"></div> | |
<div class="box box2"></div> | |
<div class="box box3"></div> | |
<script id="jsbin-javascript"> | |
function callbackFn1() { | |
$('.box1').css('background-color', 'pink'); | |
} | |
function callbackFn2() { | |
$('.box2').css('background-color', 'pink'); | |
} | |
function callbackFn3() { | |
return function() { | |
$('.box3').css('background-color', 'pink'); | |
}; | |
} | |
// callback called on done | |
$('.box1').slideDown(2000) | |
.promise() | |
.done(callbackFn1); | |
// callback called immediately because of (), which excecutes the function immediately | |
$('.box2').slideDown(2000) | |
.promise() | |
.done(callbackFn2()); | |
// this one excecutes immediately, but returns a new function, which will then be called after the slideDown promise is resolved. | |
$('.box3').slideDown(2000) | |
.promise() | |
.done(callbackFn3()); | |
</script> | |
</body> | |
</html> |
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
.box { | |
display: none; | |
width: 100px; | |
height: 100px; | |
border: 1px solid hotpink; | |
background: white; | |
margin: 10px; | |
} |
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
function callbackFn1() { | |
$('.box1').css('background-color', 'pink'); | |
} | |
function callbackFn2() { | |
$('.box2').css('background-color', 'pink'); | |
} | |
function callbackFn3() { | |
return function() { | |
$('.box3').css('background-color', 'pink'); | |
}; | |
} | |
// callback called on done | |
$('.box1').slideDown(2000) | |
.promise() | |
.done(callbackFn1); | |
// callback called immediately because of (), which excecutes the function immediately | |
$('.box2').slideDown(2000) | |
.promise() | |
.done(callbackFn2()); | |
// this one excecutes immediately, but returns a new function, which will then be called after the slideDown promise is resolved. | |
$('.box3').slideDown(2000) | |
.promise() | |
.done(callbackFn3()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment