0

我了解异步函数的原理,但我不清楚:异步函数中的范围。

例子:

    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);
    });

所以,这只是一个例子。但是它在作用域/变量中的表现如何?

4

0 回答 0