Last active
June 4, 2016 03:00
-
-
Save mrboli/6f17ff2bf746097ad3dcd78087f7f5c3 to your computer and use it in GitHub Desktop.
Callback Example for Erin Kim
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
// Async | |
function giveOrderToChef(giveFoodToCustomer){ | |
var food = makeFood(); | |
giveFoodToCustomer(food); | |
} | |
function callbackFunction(food) { | |
goToKitchen(food); | |
grabFood(food); | |
bringFoodToCustomer(food) | |
} | |
giveOrderToChef(giveFoodToCusomter); |
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
// File read example | |
import fs from 'fs'; | |
// sync | |
var fileContents = fs.readFile('./server.js', 'utf8'); | |
// async | |
fs.readFile('./server.js', 'utf8', function(data) { | |
// callback | |
}) |
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
$('document').ready(function() { | |
$('button').on('click', function() { | |
$.ajax({ | |
url: 'https://api.github.com/zen', | |
method: 'GET', | |
success: function(data) { | |
$('#text').text(data); | |
} | |
}); | |
}); | |
}); |
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
// Sychronous | |
var takeOrderAndGiveFood = getFoodForCusomter(order); | |
function getFoodForCusomter(order){ | |
var food = makeFood(); | |
// takes 20 mins. | |
grabFood(food); | |
bringFoodToCustomer(food) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment