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:
- . 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;
- . 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;
- . exit: This command exits the REPL run environment and returns to c:\users\yjh>;
- . Help: Displays all the underlying commands in the REPL environment;
- . Save: This command will save all the expressions you have entered into the specified file;
-
-
-
-
-
- Example: C:\users\yjh>node
> foo= "AaB";
' AaB '
>. Save T.js
Session saved To:t.js
>
- . Load: Loads all the expressions in the specified file into the REPL environment at once;
Section II: Interactive Runtime Environment in node. JS--REPL