gpt4 book ai didi

javascript - 从其他导出调用默认模块导出?

转载 作者:行者123 更新时间:2023-11-30 07:53:15 25 4
gpt4 key购买 nike

假设你有这个 ES6 模块:

// ./foobar.js
export default function(txt)
{
// Do something with txt
return txt;
}

是否可以向同一个文件添加另一个函数导出,使用这个默认函数?我认为这是可能的,但你怎么调用它?

// ./foobar.js
export default function(txt)
{
// Do something with txt
return txt;
}

export function doSomethingMore(txt)
{
txt = // ? how to call default function ?
// Do something more with txt
return txt;
}

最佳答案

你可以给它起个名字,它就会在范围内:

export default function foo(txt) {
// Do something with txt
return txt;
}

export function bar(txt) {
txt = foo(txt);
return txt;
}

关于javascript - 从其他导出调用默认模块导出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47602977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com