Splitting up class definition in ES 6 / Harmony

后端 未结 2 2022
独厮守ぢ
独厮守ぢ 2020-12-14 21:53

Suppose I have a class in one big file like this:

export default class {
  constructor () {}
  methodA () {}
  methodB () {}
  methodC () {}
}
2条回答
  •  执念已碎
    2020-12-14 22:27

    You should be able to, as class is supposed to just be syntax sugar for the usual prototype workflow:

    import methodOne from 'methodOne'
    import methodTwo from 'methodTwo'
    
    class MyClass {
      constructor() {
      }
    }
    
    Object.assign(MyClass.prototype, {methodOne, methodTwo})
    
    export default MyClass
    

提交回复
热议问题