下面,我尝试评估im.identify
before console.log(toObtain)
,但似乎console.log(toObtain)
是 after 调用im.identify
的。如何确保函数按照我希望它们被调用的顺序被调用?
var toObtain; //I'm trying to set the value of this variable to features (inside the callback).
var im = require('imagemagick');
im.identify('kittens.png', function(err, features){
if (err) throw err
//console.log(features);
toObtain = features;
console.log(toObtain); //this prints { format: 'PNG', width: 400, height: 300, depth: 8 }
})
console.log(toObtain); //This function call is evaluated BEFORE im.identify, which is exactly the opposite of what I wanted to do.