从节点0.4.11升级到0.6.15,并注意到REPL(没有参数的运行节点)在大多数命令或车厢返回后继续转储"未定义"...
它会分散注意力并让我感到沮丧,你怎么禁用它?
>
undefined
>
undefined
>
undefined
>
undefined
> var x = 2
undefined
> x
2
>
Run Code Online (Sandbox Code Playgroud) 我已经在debian 6上安装了nodejs 0.10.15.使用npm然后我安装了:
sudo npm install grunt-cli -g
Run Code Online (Sandbox Code Playgroud)
我还在我的本地测试目录中执行了npm install(将必要的依赖项下载到node_modules目录),其中包含以下package.json文件:
{
"name": "sample-name",
"version": "1.4.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-qunit": ">0.0.0",
"grunt-qunit-istanbul": ">0.0.0"
}
}
Run Code Online (Sandbox Code Playgroud)
这是安装phantomjs时的输出:
...
Writing location.js file
Done. Phantomjs binary available at /home/myuser/Test/node_modules/grunt-contrib-qunit/node_modules/grunt-lib-phantomjs/node_modules/phantomjs/lib/phantom/bin/phantomjs
Done. Phantomjs binary available at /home/myuser/Test/node_modules/grunt-qunit-istanbul/node_modules/grunt-lib-phantomjs-istanbul/node_modules/phantomjs/lib/phantom/bin/phantomjs
grunt@0.4.1 node_modules/grunt
??? which@1.0.5
...
Run Code Online (Sandbox Code Playgroud)
但是当我从测试目录运行grunt测试时,我得到:
Running PhantomJS...ERROR
>> In order for this task to work properly, PhantomJS must be installed locally
>> via NPM. If you're seeing this message, generally that means the NPM install …Run Code Online (Sandbox Code Playgroud) 我刚开始使用node.js.因此,从Hello World示例node.js初学者书开始.当我输入命令console.log("Hello world");.它在控制台上打印Hello World.这是我对此代码的期望,但在下一行它也打印出来undefined
我从这个链接安装nodejs用于windows的nodejs的 windows 安装
下面是截图

所以我劫持了控制台功能
var log = Function.prototype.bind.call(console.log, console);
console.log = function (a) {
log.call(console, a);
submitmsg("Log", a);
};
Run Code Online (Sandbox Code Playgroud)
这有所期望的效果,但它也会返回"未定义"作为意外奖励
我无法弄清楚为什么导致我认为这里有一点点错误

Hello world log.call(console, a)按预期生成
submitmsg() 是我的自定义功能
这正是我想要的,正如我所说的虽然我稍微担心它也因为我不理解的原因而返回"未定义".
注意: OP发布了以下代码作为问题的答案.对答案的评论已移至对该问题的评论.
所以正确的代码应该如下?
var log = Function.prototype.bind.call(console.log, console);
console.log = function (a) {
return log.call(console, a);
submitmsg("Log", a)
};
Run Code Online (Sandbox Code Playgroud)