5

我需要.js在控制台中使用 spidermonkey 运行时获取用户输入,如下所示:

$ js myprogram.js

Ruby 的 JavaScript 等价物是gets什么?

4

2 回答 2

6

据我所知,有一个 readline() 函数,但它是 spidermonkey 的特定函数,它不是 javascript 的一部分。

例子:

1)readline-test.js:

print("Type some text and press <ENTER>:\t");
var userInput = readline();
print("User input: " + userInput);

2)js readline-test.js

有关更多信息,请参阅https://developer.mozilla.org/en-US/docs/SpiderMonkey/Introduction_to_the_JavaScript_shell

于 2013-04-30T21:18:27.717 回答
0

You can't really depend on the console being there. It's not something that is guaranteed, even while most browsers do have a javascript console. Beyond that I don't believe you can get values without calling a function with the console.

于 2013-04-30T19:30:27.407 回答