【发布时间】:2016-08-30 00:32:48
【问题描述】:
我经常通过在 coffeescript 中构建类来工作,每个类都是它自己的 coffeescript 文件。然后我有一个编译器(如 Gulp)将我构建的所有不同类文件合并并缩小到一个缩小的 .js 文件中。
我的问题来自继承。由于我的编译器只是在没有任何特定顺序的情况下折腾文件,因此我可能会以下面的代码结束。
#file: otherThing.coffee
#the class "Thing" is not yet defined, this will error
class window.otherThing extends window.Thing
_prop: "that other thing"
method: () =>
super()
#file: thing.coffee
class window.Thing
_prop: "the thing"
method: () =>
console.log(@_prop)
我目前(草率)的解决方案是像这样在每个文件中提供注释。
#[COMPILE_PRIORITY:0.1]
我让编译器嗅出这些标签,并在将它们连接到单个文件时相应地对文件进行排序。
有没有更好的方法来做到这一点?
【问题讨论】:
标签: inheritance coffeescript gulp