javascript - 为什么 webpack tapable 使用 new Function('xx', 'some string code') 生成函数而不是直接写函数?
问题描述
我不明白这样做有什么好处。
我自己试了一下,发现新函数其实比直接执行代码要慢很多。
case "sync":
fn = new Function(
this.args(),
'"use strict";\n' +
this.header() +
this.content({
onError: err => `throw ${err};\n`,
onResult: result => `return ${result};\n`,
onDone: () => "",
rethrowIfPossible: true
})
);
break;
function async() {
"use strict";
some code......;
onError: err => `throw ${err};\n`,
onResult: result => `return ${result};\n`,
onDone: () => "",
rethrowIfPossible: true
}
解决方案
推荐阅读
- python - 如何使 tkinter 条目成为另一个 python 脚本中的变量
- node.js - 如何在 Facebook Messenger 上使用 MS Bot Framework 创建快速回复?
- javascript - 如何通过网络将原始数据从在 Ubuntu 上运行的 C 程序发送到 Android 设备应用程序?
- css - SVG 在中心 CSS 的 div 内缩放
- excel - 尝试在 excel VBA 中使用 Try-Catch 块获取内部异常时出错
- javascript - 如何根据javascript中的多个选项过滤嵌套数据?
- python - 如何使用 Python 编写查询?
- python - 切片字符串在末尾省略字母
- node.js - 如何在 React 中显示组件并在每次显示时更新其生命周期?
- python - 如何在不同的选项卡之间传递滑块的值?