Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I output something in Rhino?

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:

document.write{"hi"}

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

like image 567
Bentley4 Avatar asked Apr 04 '12 10:04

Bentley4


1 Answers

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

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

Rhino provides a print function.

print("hi");
like image 151
Quentin Avatar answered Sep 29 '22 13:09

Quentin