回调方式的返回值怎么提取

function d() {

        fs.exists(path,function(exists){
            var o= (exists ? "存在" : "不存在!");
            return o;
        });          
        
    }
  return d();  
    
    //我想把o赋值给function d;因为另一个文件需要o的值。
    //上面的return o 不对怎么办。
阅读 1.8k
1 个回答
function d(callback) {

        fs.exists(path,function(exists){
            var o= (exists ? "存在" : "不存在!");
            callback(o);
        });          
        
    }
function a(arg){
    console.log(arg);
}

d(a);
推荐问题