Node.js学习笔记——交互式运行环境REPL
2020-01-14 19:38
666 查看
Node.js学习笔记——交互式运行环境REPL
在REPL中:
>foo='bar'; 'bar' >var foo='bar'; undefined
使用下划线字符(访问最近使用的表达式)
>a=3; 3; >_+=1; 4 >a 3
直接运行函数
`当表达式未书写完成时,环境会自动为表达式的每一行添加英文省略符。`
>function saybbye(){ ... console.log('asd'); ... console.log('asd'); ... } undefined >//continue。。。。
REPL环境中的上下文对象
在Node.js的模块文件中,start方法返回被开启的REPL运行环境,可以为REPL运行环境指定一个上下文对象(context),可以将该上下文对象保存的变量作为REPL运行环境中的全局变量来进行使用。
//下面是index.js
var repl=require('repl'); var con=repl.start(); test=con.context; hello=10; //这里是为了说明一定是start方法返回的REPL运行环境的上下文对象才可以在REPL中被使用 test.msg='kingsley'; test.testFunction=function(){console.log(test.msg); }
//REPL环境
C:\Users\kingsley\Desktop\新建文件夹> node index.js > hello Thrown: ReferenceError: hello is not defined > msg 'kingsley' > testFunction() kingsley undefined
基础命令
-
.break
退出多行编辑环境(可以用ctrl+c代替) -
.clear
清楚REPL运行环境的上下文对象中保存的所有变量与函数(也可以推出多行编辑环境) -
.exit
退出REPL运行环境 -
.help
显示所有基础命令 -
.save
保存当前输入的所有表达式
>function print(){ ... console.log('hello kingsley'); ... } undefined > .save ../hello.js Session saved to: ../hello.js
- load
把某个文件中保存的所有表达式依次加载到REPL运行环境中
c:\Users\kingsley\Desktop\新建文件夹> node > .load../hello.js //load后面要有一个空格 Invalid REPL keyword > .load ../hello.js function print(){ console.log('hello kingsley'); } undefined > print() hello kingsley undefined >
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- NodeJS学习笔记整理(五)交互式运行环境——REPL
- Node.js权威指南 (2) - Node.js中的交互式运行环境——REPL
- node.js中的交互式运行环境-REPL
- Node.js交互式运行环境(REPL)
- Node.js中的交互式运行环境----REPL
- NodeJs>------->>第二章:Node.js中交互式运行环境--------REL
- Node.js基础知识 REPL运行环境、全局函数
- Node.js学习3- REPL(交互式解释器)
- Node.js 学习笔记--- (1)安装环境
- node.js之REPL运行环境
- ES6 学习笔记 (2)-- Liunx环境安装Node.js 与 搭建 Node.js 开发环境
- node.js 学习笔记——node.js 环境配置
- NodeJS-学习笔记(1)--windows7下node.js环境的搭建
- node.js的REPL运行环境中的基本命令汇总
- Node.js学习笔记1:windows环境搭建
- Node.js中的交互式运行环境
- Swift学习笔记(一)搭配环境以及代码运行成功
- Node.js入门学习笔记-IDE选择/配置之WebStorm(windows)
- c++学习笔记(1)——环境搭建、经典教程推荐及 Visual Studio 2005/2008中如何编译和运行C++程序
- Swift学习笔记(一)搭配环境以及代码运行成功