Last active
August 29, 2015 14:01
-
-
Save blackbing/a9dad5c141f51b65b650 to your computer and use it in GitHub Desktop.
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
query = (task, callback)-> | |
#do something | |
callback(task + ' finished') | |
#nested way | |
query('task1', (msg)-> | |
console.log msg | |
query('task2', (msg)-> | |
console.log msg | |
query('task3', (msg)-> | |
console.log msg | |
) | |
) | |
) | |
#function call function | |
task1 = -> | |
query('task1', (msg)-> | |
console.log 'function ' + msg | |
task2() | |
) | |
task2 = -> | |
query('task2', (msg)-> | |
console.log 'function ' + msg | |
task3() | |
) | |
task3 = -> | |
query('task3', (msg)-> | |
console.log 'function ' + msg | |
) | |
task1() | |
#Deferred | |
query_dfr = (task)-> | |
_dfr = $.Deferred() | |
query(task, (msg)-> | |
_dfr.resolve(msg) | |
) | |
_dfr.promise() | |
query_dfr('task1') | |
.pipe((msg)-> | |
console.log ('Deferred ' + msg ) | |
query_dfr('task2') | |
).pipe((msg)-> | |
console.log ('Deferred ' + msg ) | |
query_dfr('task3') | |
).pipe( (msg)-> | |
console.log ('Deferred ' + msg ) | |
) |
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-2.1.0.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment