2

我有以下代码,当我尝试使用命令将其加载到我的交互式节点控制台时出现错误.load myFile.js

var Q=require('q');
var promise1 = function(x){
    var def = Q.defer();
    setTimeout(function(){
        def.resolve(x*5);
    },3000);
    return def.promise;
};

var process = function(val){
    promise1(val);
};

这是我的错误:

Failed to load:myFile.js

_stream_writable.js:258
      process.nextTick(function() {
              ^
TypeError: Object function (val){
promise1(val);
} has no method 'nextTick'
    at onwrite (_stream_writable.js:258:15)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at WriteStream.Socket._write (net.js:651:5)
    at doWrite (_stream_writable.js:219:10)
    at writeOrBuffer (_stream_writable.js:209:5)
    at WriteStream.Writable.write (_stream_writable.js:180:11)
    at WriteStream.Socket.write (net.js:613:40)
    at REPLServer.repl.defineCommand.action (repl.js:858:27)
    at REPLServer.parseREPLKeyword (repl.js:670:16)
    at Interface.<anonymous> (repl.js:219:16)

知道为什么吗?

4

1 回答 1

4

process是一个内置的 Node.js 全局。

通过在 REPL 中创建自己的process变量(它没有自己的范围),你破坏了一切。

于 2013-08-16T19:50:13.747 回答