Skip to content

Instantly share code, notes, and snippets.

@IOExceptional
Created February 15, 2016 14:01
Show Gist options
  • Save IOExceptional/0bcf38835638cce60cba to your computer and use it in GitHub Desktop.
Save IOExceptional/0bcf38835638cce60cba to your computer and use it in GitHub Desktop.
There's something that behaves strangely in this code, what's wrong? Tip: Mutable variables and closures.
var doStuff = function($scope) {
var model = [];
var items = $scope.items;
for(var i = 0; i < items.length; i++) {
var source = items[i];
doAsyncThings().then(function(newValue){
model[i].src = newValue;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment