自定义评估函数


\Custom evaluation functions

当新建 repl.REPLServer 时,可能会提供自定义评价函数。例如,这可用于实现完全定制的 REPL 应用。

\When a new repl.REPLServer is created, a custom evaluation function may be provided. This can be used, for instance, to implement fully customized REPL applications.

以下说明了一个 REPL 的假设示例,该示例执行将文本从一种语言翻译成另一种语言:

\The following illustrates a hypothetical example of a REPL that performs translation of text from one language to another:

const repl = require('node:repl');
const { Translator } = require('translator');
const myTranslator = new Translator('en', 'fr');
function myEval(cmd, context, filename, callback) {
 callback(null, myTranslator.translate(cmd));
}
repl.start({ prompt: '> ', eval: myEval }); 

AltStyle によって変換されたページ (->オリジナル) /