【发布时间】:2018-10-01 09:01:39
【问题描述】:
上下文:
我目前正在使用 Phaser 框架开发游戏。我得到了一个可以使用的代码库,因此无法更改。 Phaser 没有原生的导入/导出方式,所以我使用 webpack 和 babel 来绕过with lots of help from this template.
我的问题源于尝试导入和导出以下代码:
给定代码:
AchievementManager = function(a) {
this.game = a,
this._playerDataModified = !1,
this.newLevels = [],
};
AchievementManager.prototype = {
_getTotalLoyaltyPoints: function() {
return 1;
}
}
我尝试导出。返回编译错误(不在浏览器中)“模块构建失败:SyntaxError: Unexpected token, expected {' in reference to AchievementManager:
export AchievementManager = function(a) {
this.game = a,
this._playerDataModified = !1,
this.newLevels = [],
};
export AchievementManager.prototype = {
_getTotalLoyaltyPoints: function() {
return 1;
}
}
如果有人可以帮助我了解如何导出/导入以这种形式编写的类,同时保持原型功能等核心概念,那就太好了!
【问题讨论】:
标签: javascript webpack phaser-framework es6-modules