【发布时间】:2015-03-05 09:47:08
【问题描述】:
我想写一个可变的 write() 函数。
var write = function(s) {
process.stdout.write(s);
}
write("Hello world!");
我想你可以把它写得更短:
var write = process.stdout.write;
write("Hello world!");
但是在这里我会收到这个错误:
TypeError: Cannot read property 'defaultEncoding' of undefined
at Writable.write (_stream_writable.js:172:21)
at Socket.write (net.js:613:40)
at repl:1:2
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
为什么会这样?
【问题讨论】: