【发布时间】:2017-05-21 22:56:31
【问题描述】:
所以我遇到了在 Webpack 中扩展超类的子类的问题。
我的超类:core/Main.js
class Main {
constructor () {
console.log('Main Class Initialized');
}
}
module.exports = Main;
子类:app/Launch.js
var Main = require('core/Main.js');
class Launch extends Main {
constructor () {
console.log('Before Super')
super();
console.log('Launch Class Initialized')
}
}
如果我在 app/Launch.js 文件中 console.log(Main) 它会记录 Main 并且“Before Super”也会被记录,但调用 super() 会导致它中断,我不知道为什么。
How to achieve inheritance in ES6 with “webpack module bundler”? 没有帮助。我尝试将module.exports 换成export class Main {} 和require('core/Main.js') 换成import {Main} from 'core/Main.js',但是没有用。使用 webpack 1.14.0。
【问题讨论】:
-
继承与 webpack 无关。看来您的问题实际上类似于“使用 webpack 时如何正确导入模块”?
标签: javascript inheritance webpack es6-class