vm.compileFunction(code[, params[, options]])


    将给定的代码编译到提供的上下文中(如果没有提供上下文,则使用当前上下文),并返回它包装在具有给定 params 的函数中。

    • code <string> The body of the function to compile.
    • params <string[]> An array of strings containing all parameters for the function.
    • options <Object>
      • filename <string> Specifies the filename used in stack traces produced by this script. Default: ''.
      • lineOffset <number> Specifies the line number offset that is displayed in stack traces produced by this script. Default: 0.
      • columnOffset <number> Specifies the first-line column number offset that is displayed in stack traces produced by this script. Default: 0.
      • cachedData <Buffer> | <TypedArray> | <DataView> Provides an optional Buffer or TypedArray, or DataView with V8's code cache data for the supplied source.
      • produceCachedData <boolean> Specifies whether to produce new cache data. Default: false.
      • parsingContext <Object> The contextified object in which the said function should be compiled in.
      • contextExtensions <Object[]> An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling. Default: [].
      • importModuleDynamically <Function> Called during evaluation of this module when import() is called. If this option is not specified, calls to import() will reject with ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING. This option is part of the experimental modules API, and should not be considered stable.
        • specifier <string> specifier passed to import()
        • function <Function>
        • importAssertions <Object> The "assert" value passed to the optionsExpression optional parameter, or an empty object if no value was provided.
        • Returns: <Module Namespace Object> | <vm.Module> Returning a vm.Module is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain then function exports.
    • Returns: <Function>

    Compiles the given code into the provided context (if no context is supplied, the current context is used), and returns it wrapped inside a function with the given params.