对于工作测试,我需要像这样创建库:
// do-it.js
function doIt(smth) {}
module.exports = {
doIt,
};但我使用的是typescript和编译后的do-it.ts文件,如下所示:
// do-it.js when compiled from do-it.ts
exports.__esModule = true;
exports.doIt= exports.another = void 0;
function doIt(smth) {}
exports.doIt = doIt;
function another() {}
exports.another= another;从这两个示例中导出的效果是否相同?
发布于 2021-05-02 01:15:21
粗略地说,是的;当然,由此产生的输出是相同的。
我是说,如果你有:
module.exports = {
doIt,
};后来也做到了
module.exports = {
doSomethingElse,
};您会遇到一个问题,因为第二个完全替换了前面的exports对象。
你根本不需要创建这个对象,它是在你的模块被调用之前为你创建的。所以真的,你可以这样做
exports.doIt = doIt;然后
exports.doSomethingElse = doSomethingElse;首先。
https://stackoverflow.com/questions/67348878
复制相似问题