Section II: Interactive Runtime Environment in node. JS--REPL

Source: Internet
Author: User

1. What is the REPL operating environment: to make it easy for developers to test JavaScript code, an interactive runtime environment called REPL (Read-eval-print-loop) is provided.

2. How to use: In the Command Line window, enter the "node" command and press ENTER to enter the REPL running environment.

3. Declare the object and assign a value to the property:

> User=new Object ();
{}
> user.name= ' Yjh ';
' Yjh '
> user.age=20;
20
> user.setname=function (name) {This.name=name}
[Function]

4. The "_" underline indicates the most recently used expression

> age=2;
2
> _+=1;
3

5..start method, for example in module REPL, is to return the REPL running environment that is turned on

In the Starttest2.js file:

var repl=require ("Repl");
var con=repl.start (). Context; Specify a context for the REPL run environment
Con.msg= "Zhang Zhao";
Con.testfunction=function () {console.log (con.msg);};

On the command line:

C:\users\yjh>node C:\Users\yjh\Desktop\startTest2.js
> Msg
' Zhang Zhao '
> TestFunction ();
Zhang Zhao
Undefined

Basic commands in the 6.REPL runtime environment:

  1. . Break: When you want to discard or override this function halfway through writing a multiline function, return to the beginning of the command prompt: >;     CTRL + C equals. break; CTRL + C two times will launch REPL environment;
  2. . Clear: To clear all variables and functions stored in the context object of the REPL run environment, and to return to the beginning of the command prompt when you want to discard or override this function halfway through writing a multiline function: >; Similar to the. break;
  3. . exit: This command exits the REPL run environment and returns to c:\users\yjh>;
  4. . Help: Displays all the underlying commands in the REPL environment;
  5. . Save: This command will save all the expressions you have entered into the specified file;
              1. Example: C:\users\yjh>node
                > foo= "AaB";
                ' AaB '
                >. Save T.js
                Session saved To:t.js
                >
  6. . Load: Loads all the expressions in the specified file into the REPL environment at once;

Section II: Interactive Runtime Environment in node. JS--REPL

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.