我想在我的里面写这样的东西src/core/Chessman.js
file:
import King from './chessmen/King'
class Chessman {
static factory(side, quality) {
switch(quality) {
case 'king' : return new King(side) break
// ... other qualities
}
constructor(side) { this.side = side }
cast(position, ref) { }
run(position, startRef, endRef) {}
}
在我的里面src/core/chessmen/King.js
file:
import Chessman from '../Chessman'
class King extends Chessman {
constructor(side) {
super(side)
this.iterative = false // true for Queens, Rooks and Bishop
this.directions = [
'up', 'up+right', 'right', 'right+down',
'down', 'down+left', 'left', 'left+top'
]
}
// overrides parent behavior
cast(position, ref) {}
run(position, startRef, endRef) {}
}
但遗憾的是我在使用 Karma、jasmine 和 babel 时遇到了错误(在测试时)
类型错误:超级表达式必须为 null 或函数,而不是未定义
在 src/core/chessmen/King.js:57
目前还没有 57 号线King.js
!