“process.stdout.write”之间的区别和“console.log”在node.js? [英] Difference between "process.stdout.write" and "console.log" in node.js?

查看:1055
本文介绍了“process.stdout.write”之间的区别和“console.log”在node.js?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

node.js中process.stdout.write和console.log有什么区别?

What is the difference between "process.stdout.write" and "console.log" in node.js?

编辑:使用console.log作为变量在使用process.stdout.write显示一个对象时显示了很多不可读的字符。

Using console.log for a variable showed a lot of unreadable characters while using process.stdout.write showed an object.

为什么会这样?

推荐答案

console.log()使用格式化调用 process.stdout.write 输出。请参阅console.js中的 format()以了解实现。

console.log() calls process.stdout.write with formatted output. See format() in console.js for the implementation.

目前(v0.10.ish):

Currently (v0.10.ish):

Console.prototype.log = function() {
  this._stdout.write(util.format.apply(this, arguments) + '\n');
};

这篇关于“process.stdout.write”之间的区别和“console.log”在node.js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆