script.createCachedData()
- 返回: <Buffer>
创建一个可以被 Script
构造函数中 cachedData
选项使用的代码缓存。返回 Buffer
。可以在任何时候不限次数地调用该方法。
const script = new vm.Script(`
function add(a, b) {
return a + b;
}
const x = add(1, 2);
`);
const cacheWithoutX = script.createCachedData();
script.runInThisContext();
const cacheWithX = script.createCachedData();
- Returns: <Buffer>
Creates a code cache that can be used with the Script
constructor's
cachedData
option. Returns a Buffer
. This method may be called at any
time and any number of times.
const script = new vm.Script(`
function add(a, b) {
return a + b;
}
const x = add(1, 2);
`);
const cacheWithoutX = script.createCachedData();
script.runInThisContext();
const cacheWithX = script.createCachedData();