Node.js REPL中的'clearBufferedCommand()方法有什么作用

时间:2019-09-05 18:37:15

标签: node.js

Node.js中的'clearBufferedCommand()'方法有什么用途?

此代码来自Node.js规范,但我看不到对此方法的任何使用。

const repl = require('repl');

const replServer = repl.start({ prompt: '> ' });
replServer.defineCommand('sayhello', {
    help: 'Say hello',
    action(name) {
        this.clearBufferedCommand();
        console.log(`Hello, ${name}!`);
        this.displayPrompt();
    }
});

1 个答案:

答案 0 :(得分:1)

来自docs

  

replServer.clearBufferedCommand()方法清除所有   已被缓冲但尚未执行。这种方法主要是   旨在从动作函数内调用命令   使用replServer.defineCommand()方法注册。