ES6 中是否有针对 ES5 `module.exports = require('./inner.js')` 的单行类比? [英] Is there any one-line analogy in ES6 for ES5 `module.exports = require('./inner.js')`?

查看:21
本文介绍了ES6 中是否有针对 ES5 `module.exports = require('./inner.js')` 的单行类比?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// before
module.exports = require('./inner.js');
// nowadays
export default from './inner.js';

我正在尝试这样做,但是 babel 只在 es7 阶段 1 中允许它,因为它是 现在的提议.所以现在,我坚持这两行:

i'm trying to do this, but babel allow it only in es7 stage 1 as it is proposal for now. So for now, im stick to these two lines:

import sticker from './box-sticker.jsx';
export default sticker;

我可以将它们缩短为一个吗?

Can I shorter them to one?

推荐答案

你应该可以做到

export {default as default} from './inner.js';
// or even
export {default} from './inner.js';

使用当前的 ES6 语义.

with current ES6 semantics.

不过我不认为使用 ES 下一个提案有什么问题,我非常有信心它会进入 ES7 ES8.

However I don't think there's anything wrong with using the ES next proposal, I'm pretty confident that it will make it into ES7 ES8.

这篇关于ES6 中是否有针对 ES5 `module.exports = require('./inner.js')` 的单行类比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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