Event: 'exit' function () {} 当用户通过预定义的方式退出 REPL 将会触发这个事件。预定义的方式包括,在 repl 里输入 .exit,按 Ctrl+C 两次来发送 SIGINT 信号,或者在 input 流上按 Ctrl+D 来发送"end"。 监听 exit 的例子: - r.on('exit', function () {
- console.log('Got "exit" event from repl!');
- process.exit();
- });
复制代码 Event: 'reset'function (context) {} 重置 REPL 的上下文的时候触发。当你输入.clear会重置。如果你用 { useGlobal: true } 启动 repl,那这个事件永远不会被触发。 监听 reset 的例子: - // Extend the initial repl context.
- r = repl.start({ options ... });
- someExtension.extend(r.context);
- // When a new context is created extend it as well.
- r.on('reset', function (context) {
- console.log('repl has a new context');
- someExtension.extend(context);
- });
复制代码
|