Nodejs环境下控制台拼接字符串输出有undefind
今天在Nodejs环境下搓小工具,控制台输出拼接字符串时,发现有undefind
,代码如下:
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth();
const day = date.getDate();
const hour = date.getHours();
const minute = date.getMinutes();
const second = date.getSeconds();
const logTime = `[${year}-${month}-${day} ${hour}:${minute}:${second}] `;
class GenerateLog {
static log() {
process.stdout.write(logTime);
}
}
console.log(GenerateLog.log() + "log output on the console");
输出确是这样:
……