简体   繁体   English

从Webpack中导入模块的ES6继承

[英]ES6 Inheritance From Imported Module in Webpack

So I'm having issues with sub-classes extending a super class in Webpack. 所以我在扩展Webpack中的超类的子类方面遇到了问题。

My super class: core/Main.js 我的超类:core / Main.js

class Main {
    constructor () {
        console.log('Main Class Initialized');
    }
}

module.exports = Main;

Sub-class: app/Launch.js 子类:app / Launch.js

var Main = require('core/Main.js');
class Launch extends Main {

    constructor () {
        console.log('Before Super')
        super();
        console.log('Launch Class Initialized')
    }
}

If I console.log(Main) inside of the app/Launch.js file it logs Main and 'Before Super' also gets logged, but calling super() causes it to break and I have no idea why. 如果我在app / Launch.js文件内的console.log(Main)记录了Main并且'Before Super'也被记录了,但是调用super()导致它损坏,我也不知道为什么。

How to achieve inheritance in ES6 with “webpack module bundler”? 如何使用“ webpack module bundler”在ES6中实现继承? didn't help. 没有帮助。 I tried swapping out module.exports for export class Main {} and require('core/Main.js') for import {Main} from 'core/Main.js' , but it didn't work. 我尝试将module.exports export class Main {}并将require('core/Main.js') import {Main} from 'core/Main.js' ,但这没有用。 Using webpack 1.14.0. 使用webpack 1.14.0。

Got it. 得到它了。 I copied Main.js into app/ and required that. 我将Main.js复制到app/并要求。 Works fine now, don't know why that made a difference though. 现在可以正常工作,但不知道为什么会有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM