在ES6中导出常量的正确方法是什么? [英] What is the correct way to export a constant in ES6?

查看:76
本文介绍了在ES6中导出常量的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的输入文件分解为组件,但我不确定如何使常量可用于导入。这是我到目前为止所尝试的并且两者似乎都有效:

I'm trying to break my entry file into components but I'm not sure how to make the constant available to the import. This is what I've tried so far and both seem to work:

export const ConnectedRange = connectRange(Range);

exports.ConnectedRange = connectRange(Range);

我已经看到后者在一些npm包中使用但确定要使用什么?

I've seen the latter used in some npm packages but sure what to use?

谢谢

推荐答案


export const ConnectedRange = connectRange(范围);

export const ConnectedRange = connectRange(Range);

是ES模块的语法。


exports.ConnectedRange = connectRange(Range);

exports.ConnectedRange = connectRange(Range);

是commonJS语法。

Is the commonJS syntax.

我建议使用ES模块语法,如果您运行代码的环境不支持ES模块,则编译为通用JS。

I would recommend using the ES modules syntax, and compiling to common JS if the environment you run your code on does not support ES modules.

这篇关于在ES6中导出常量的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆