javascript async interpreter. Through it, dynamically updates codes can be implemented
npm install ieval
English
|
中文文档
javascript
npm install ieval
`
#### DocumentEval Class
` javascript
import {DocumentEval} from 'ieval';// To set the URL request, 'ieval' needs to return a complete executable code string via 'Promise'
DocumentEval.setNetwork(url => {
return new Promise(resolve => {
wx.request({
url: url,
success: data => {
resolve(data.data);
},
})
});
});
// This environment variable is especially important because it is needed for system objects that we depend on in our JS code, such as window global document
// If the code currently executing does not need the system object we can leave it blank to avoid security issues during execution
const context = {};
const ieval = new DocumentEval(context);
// Insert your URL connection in the context
ieval.appendUrl('https://image.xxx.com/echarts.js');
ieval.appendUrl('https://image.xxx.com/vue.js');
// We then use 'getWindow' to get the global variable declared in the code we execute
const ctx = await ieval.getWindow();
// run.
ctx.echarts.init();
`#### iEval Function
` javascript
import {iEval} from 'ieval';
// We then use 'getWindow' to get the global variable declared in the code we execute
// If the code currently executing does not need the system object we can leave it blank to avoid security issues during execution
const context = {};
// Insert your URL connection in the context
const ieval = iEval(['console.log("start.")', 'https://image.xxx.com/echarts.js', 'https://image.xxx.com/vue.js','console.log("end.")'], context);const ctx = await ieval.getWindow();
// run.
ctx.echarts.init();
``##### In this way we have implemented a basic resource load execution