2

我有以下 javascript:

#!/usr/bin/env node
var fs = require(’fs’);
var outfile = "hello.txt";
var out = "Modify this script to write out something different.\n";
fs.writeFileSync(outfile, out);
console.log("Script: " + __filename + "\nWrote: " + out + "To: " + outfile);

在执行以下命令时:

node test.js
cat hello.txt

我得到以下输出:

[object Object]

我究竟做错了什么?

4

1 回答 1

0

你得到一个作为字符串返回的对象。您将需要找出对象具有的属性并返回它们,或者遍历对象并显示属性,或者将其转换为字符串...

console.log(JSON.stringify(objToJson));
于 2013-07-24T14:20:32.060 回答