Skip to content

Instantly share code, notes, and snippets.

@tehnrd
Created September 10, 2014 19:30
Show Gist options
  • Save tehnrd/48ec15fbd75cfa5077ae to your computer and use it in GitHub Desktop.
Save tehnrd/48ec15fbd75cfa5077ae to your computer and use it in GitHub Desktop.
// See the question in the callback function
function getContacts() {
var accountId;
//Some code that dynamically sets accountId would be here
$.get("/contacts.json?accountId=" + accountId, function( data ) { //This is an asynchronous callback function
/*This inside an anonymous function executing asynchronously in a seperate context from when getContacts()
was originally called but it still has the ability to read the value in the 'accountId' var.
Why? What is this commonly refered to.*/
console.log('I see you ' + accountId);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment