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

标签 javascript ecmascript-6 es6-modules

假设你有这个 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/

相关文章:

javascript - DataTables column().search() - 按字符串中的开头字母搜索

JavaScript 将嵌套 Map 转换为对象

javascript - 为什么将 Arrow 函数体包裹在括号中

javascript - ESlint - import.meta 导致致命解析错误

javascript - <li> 使用 jquery 可排序 onDrop 事件进行克隆

JavaScript - 连接两个数字并将结果视为数字

javascript - 避免在 ES6 中的函数内定位 this 的对象范围

node.js - 在带有 ES 模块的 Node.js 中使用相对路径导入

es6-modules - 如何使用 ES6 导入(客户端 JS)

javascript - 使用 'findOne' 或 'findAll' 后 Sequelize 不会更新