Skip to content

Instantly share code, notes, and snippets.

@captainkovalsky
Created January 14, 2015 22:06
Show Gist options
  • Save captainkovalsky/79af167b117ae4fe4dfd to your computer and use it in GitHub Desktop.
Save captainkovalsky/79af167b117ae4fe4dfd to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
var objects = [
{"id":1, "content":""},
{"id":2, "content":""},
{"id":3, "content":""}
];
function deferredLoad(id, cb){
setTimeout(function(){
cb("content for " + id);
},4000);
objects.forEach(function(v, i, arr){
deferredLoad(v.id, function(content){
console.log('content : ', cotent);
//update content of object via closure I think
});
});
console.log(objects);
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">var objects = [
{"id":1, "content":""},
{"id":2, "content":""},
{"id":3, "content":""}
];
function deferredLoad(id, cb){
setTimeout(function(){
cb("content for " + id);
},4000);
objects.forEach(function(v, i, arr){
deferredLoad(v.id, function(content){
console.log('content : ', cotent);
//update content of object via closure I think
});
});
console.log(objects);
}</script></body>
</html>
var objects = [
{"id":1, "content":""},
{"id":2, "content":""},
{"id":3, "content":""}
];
function deferredLoad(id, cb){
setTimeout(function(){
cb("content for " + id);
},4000);
objects.forEach(function(v, i, arr){
deferredLoad(v.id, function(content){
console.log('content : ', cotent);
//update content of object via closure I think
});
});
console.log(objects);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment