View the execution environment using the JS interpreter rhino

Source: Internet
Author: User

Rhino is a Mozilla open-source javascript interpreter written by Java.

Document address https://developer.mozilla.org/en/Rhino_documentation

Installation Method http://www.terminally-incoherent.com/blog/2008/01/08/rhino-scripting-java-with-javascript

Install.

Sudo apt-Get install rhino in Ubuntu

Then write a. js file with the following content:

 
Print ("Hello World ")

Enter rhino A. js in the terminal. The input Hello world is displayed.

In rhino, the variable object in the JS execution environment can be returned. Pass _ parent __

 
Function f () {var Bob = 'hello'; var inner = function () {}; var parent = inner. _ parent __; var contents = ''; For (K in parent) contents + = K +''; print (contents);} f ();

Output: arguments Bob inner parent Contents

Take a lookCodeWhat will be output?

Function A () {var a2 = "in"; return function () {var B = 2; return B;} var B = a (); var contents = ''; for (K in B. _ parent _) contents + = K + ''; print (contents)

Output: arguments A2

What are described above? The scope chain of function B has been created when the function is defined.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.