I know that objects are copied by reference in javascript, but this is strange.
var project = projects[projectIndex];
var projectName = project[0]["repository"]["name"];
console.log("type" + " of name " + projectName + " in " + ownerFolderName);
projectTasks.push(function(callback){
omnifocus.create_folder_if_possible_in_group(projectName, ownerFolderName, function () {
callback();
});
});
In this snippet is run multiple times in a loop. The projectName
is correct when logged with console.log
. However, when used in the anonymous function (in projectTasks
), the value is always the same value as the last item.
For example : if it's looped three times, it will log "1", "2", "3" (which is correct). However, in the anonymous function, it will run three times with the "3" value.
Full code is available here : https://github.com/gcamp/github-omnifocus-sync/blob/master/index.js