下面的文件是 vanilla.js,文本编辑器是 ATOM,使用终端在 nodejs 上运行。代码片段如下:
'use strict';
const Readline = require('readline');
const rl = Readline.createInterface({
input:process.stdin,
output:process.stdout,
terminal: false
});
rl.setPrompt('> ');
rl.prompt();
rl.on('line', reply => {
console.log('You said ${reply}');
});
用户输入 Hi 后,输出为 You said ${reply}
$ node app.js
> hi
You said ${reply}
你打招呼的地方
目前正在使用 Python v8.9.1
我是否遗漏了代码或任何所需的依赖项。参见 screenshots附上。
问候, 尼玛
最佳答案
You need to use backticks `
in order to use template strings.您需要更改代码中的这一行:
console.log('You said ${reply}');
到
console.log(`You said ${reply}`);
另请查看 this JSFiddle
关于javascript - console.log ('You said ${reply}' 的输出问题;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47788994/