仅为副作用而导入的 ES6 模块的公认做法? [英] Accepted practice for an ES6 module imported just for side-effects?

查看:26
本文介绍了仅为副作用而导入的 ES6 模块的公认做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢保持我的代码模块化,所以我把这种代码放在一个单独的文件中(overrides/extra.js):

I like to keep my code modular, so I put this kind of code in a separate file (overrides/extra.js):

import Ember from 'ember';

Ember.RSVP.configure('onerror', function(error) {
    ....
});

export default null;

这只有配置 Ember.RSVP 的副作用,但不会导出任何有价值的东西.然后我会在 app.js 中导入它:

This has only the side effect of configuring Ember.RSVP but does not export anything of value. I would then import this in app.js:

import dummy from './overrides/extra';

这是公认的做法吗?

推荐答案

是的,如果您的模块不需要导出任何数据,但不需要从模块导出任何内容,这是接受如果不需要:

Yes this is accepted if your module doesn't need to export any data, but there's no need to export anything from a module if it's not required:

import Ember from 'ember';

Ember.RSVP.configure('onerror', function(error) {
    ....
});

app.js:

import './overrides/extra';

这篇关于仅为副作用而导入的 ES6 模块的公认做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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