ES6 / 7中的循环依赖 [英] Circular dependencies in ES6/7
问题描述
我很惊讶地发现在Babel中,我可以有两个模块 import
,没有任何问题。我发现有一些地方将此称为Babel中已知和预期的行为。我知道这被人们广泛认为是一种反模式(我猜的最多),但请忽略这个问题:
I was surprised to find that in Babel, I could have two modules import
each other without any issues. I have found a few places that refer to this as a known and expected behaviour in Babel. I know that this is widely considered an anti-pattern by a lot of (I'm guessing most) people, but please ignore that for this question:
有谁知道如果这是(或将是)ES6 / 7中的正确行为?
Does anyone know if this is (or will be) correct behaviour in ES6/7?
我能找到的官方答案(和技术解释)最接近的是对2ality.com的评论
The closest thing I can find to an official answer (and technical explanation) is this comment on 2ality.com
推荐答案
通常认为这是不好的做法。但ES模块旨在支持循环依赖。 ES 2017规范中有一些信息 15.2.1.16.3ResolveExport具体方法。但是,我觉得这很难读(老实说,我受了很多苦)。您在2ality.com上提到的帖子可能更易阅读。
It's usually considered bad practices. But ES modules are designed to support cyclic dependencies. There are some information in ES 2017 spec 15.2.1.16.3ResolveExport Concrete Method. However, I think it's really hard to read (to be honest, I suffer a lot). The post you mentioned from 2ality.com might be better readable.
这篇关于ES6 / 7中的循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!