【发布时间】:2012-09-14 11:01:13
【问题描述】:
下面,我尝试在console.log(toObtain) 之前评估im.identify,但似乎console.log(toObtain) 在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.
【问题讨论】:
-
这个问题好像有重复:stackoverflow.com/questions/9121902/…
标签: node.js