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


  • code <string> 需要编译的函数体。
  • params <string[]> 包含所有函数参数的字符串数组。
  • options <Object>
    • filename <string> 定义此脚本生成的堆栈跟踪信息中使用的文件名。 默认值: ''
    • lineOffset <number> 定义此脚本生成的堆栈跟踪信息中显示的行号偏移量。默认值: 0
    • columnOffset <number> 定义此脚本生成的堆栈跟踪中显示的列偏移量。 默认值: 0
    • cachedData <Buffer> | <TypedArray> | <DataView> 为源码提供一个 BufferTypedArrayDataView 格式的 V8 代码缓存。
    • produceCachedData <boolean> 定义是否需要生成新的缓存数据。默认值: false
    • parsingContext <Object> 编译函数的上下文隔离化的对象。
    • contextExtensions <Object[]> 包含要在编译时应用的上下文扩展(包装当前范围的对象)的集合的数组。默认值: []
  • 返回: <Function>

将给定的代码编译到提供的上下文中(如果没有提供上下文,则使用当前上下文),并返回包装了给定 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 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: [].
  • 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.