System.import承诺链接

Est*_*ask 4 javascript promise ecmascript-6 systemjs

我偶然发现了一些与此类似的片段:

  System.import('core-js').then( function() {
    System.import('polymer/mutationobservers').then( function() {
      System.import('aurelia-bootstrapper');
    })
  });
Run Code Online (Sandbox Code Playgroud)

它是否代替回调地狱 - 一个承诺地狱?顺序System.imports可以扁平化以使用承诺链,或者可能存在问题吗?

log*_*yth 9

我推荐链接,例如

System.import('core-js')
    .then(function(){
        return System.import('polymer/mutationobservers');
    })
    .then(function(){
        return System.import('aurelia-bootstrapper');
    });
Run Code Online (Sandbox Code Playgroud)

当你return从a承诺时then,它会在执行下一个之前等待解决then,所以在这种情况下mutationobservers必须先加载aurelia-bootstrapper.