Linux 如何在 Rhino 中输出一些东西?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10009620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:36:51  来源:igfitidea点击:

How do I output something in Rhino?

javascriptlinuxrhino

提问by Bentley4

I'm looking for the javascript equivalent of Python2.x's print "hi". I'm working with the Rhino javascript interpreter in the ubuntu terminal. When I type:

我正在寻找等效于 Python2.x 的 javascript print "hi"。我正在 ubuntu 终端中使用 Rhino javascript 解释器。当我输入:

document.write{"hi"}

I get the error that 'document' is not defined.

我收到未定义“文档”的错误。

采纳答案by Quentin

JavaScript doesn't have any built in methods to provide output. Scripts have to depend on features provided by the host environment for that.

JavaScript 没有任何内置方法来提供输出。脚本必须依赖于宿主环境为此提供的功能。

documentis an object that is available in web browsers, but not in Rhino. Even if it was available, document.writeis a function. You use ()to call a function, not {}.

document是一个在 Web 浏览器中可用的对象,但在 Rhino 中不可用。即使它可用,document.write也是一种功能。你()用来调用一个函数,而不是{}.

Rhino provides a printfunction.

Rhino 提供了一个print功能。

print("hi");

回答by zaf

I don't think you have access to the 'document' object - as the one I think you're referring to is only available when javascript is run in the browser.

我认为您无权访问“文档”对象 - 因为我认为您所指的对象仅在浏览器中运行 javascript 时才可用。

Also, use normal brackets rather than curly brackets to invoke functions.

此外,使用普通括号而不是大括号来调用函数。

Just try:

你试一试:

print('Hello, world!')