node.js - 如何在nodejs中的函数之外评估()?
问题描述
我不确定这是否可能,但我正在寻找 eval 并在调用它的函数范围之外访问 eval 代码。
我当前的代码:
test.importDependencies = () => 'function myDep() {}'
eval(test.importDependencies())
myDep()
我希望它是什么:
test.importDependencies = () => 'function myDep() {}'
test.importDependencies()
myDep()
这样做的原因是我正在为 Google App Script 编写代码,它不使用 require,一切都在全局范围内。但是我想在节点中编写一些单元测试,并且我不想在我的代码中使用 require 语句,因为它会使我的构建过程复杂化。
解决方案
推荐阅读
- html - 如何对齐 Bootstrap 表单的输入字段和标签?
- mysql - 如何使用月份名称获取最近 3 个月的计数,如果该月份没有记录需要使用月份名称获取 0
- java - 为我的 Java 应用程序 Jar 文件创建 Linux 可执行文件
- spring - 使用拦截 url 模式访问
- javascript - 如何在角度通用的特定路线上进行 SSR?
- reactjs - Refactoring almost identical components, formik react
- c# - 使用 XAML 在 WPF 应用程序中使用 RGB 设置 WinForms 控件 BackColor?
- c# - 如何将 c# 代码转换为 perl 或 openssl cli?
- android - 如何在android的运行时获取.aar符号(或HashKey)
- spring-boot - 更改 appender 级别而不是 logger 级别