ES6 类在通过系统导入时不是一个函数

ES6 Class is not a function when imported via System

本文关键字:函数 一个 导入 系统 ES6      更新时间:2023-09-26

为什么通过系统导入时游戏不是一个函数

import Core from 'gameUnits/Core' 
export class Game { 
constructor() {

核心:

export class Core {
    constructor(scene) {
    }
}

并在浏览器中:

     <script src="bower_components/traceur/traceur.js"></script>
  <script src="bower_components/es6-module-loader/dist/es6-module-loader.js"></script>
  <script>
    System.import('Game').then(function (Game) {
      game = new Game();
    });
  </script>

您情况下的模块对象不是Game,它包含Game 。尝试:

System.import('Game').then(function ({Game}) {
  game = new Game();
});