使用异步函数在node.js中进行作用域

时间:2013-11-07 18:14:08

标签: javascript node.js asynchronous

我理解异步函数的原理,但我不清楚:异步函数中的作用域。

示例:

    var path = "/my/folder/to/public/data";
    http.createServer(function(request, response){
            /* some malicious code is executed, however */
            path = "/my/folder/to/private/data"
    });

    /* go on, go on, go on, wait here because of an synchronous function. */
    /* while code execution is here, the callback-function of the server is called. */

    fs.readFile(path+"myfile.txt", function(err, content){
            console.log(content);
    });

所以,这只是一个例子。但是它如何与范围/变量一起表现?

0 个答案:

没有答案