有示例:
B级
A 类扩展 B 类
命令:coffee -w -j main.js -c -l -o lib src
错误:未捕获类型错误:无法读取未定义的属性“原型(prototype)”
原因 : ClassA 在编译文件中先于 B 编译,所以 classB 还不存在 ClassA 已创建并尝试扩展它..
愚蠢的修复:ClassA重命名为ClassC,因此在编译文件中将在ClassB之后编译
有人得到了更好的修复?
谢谢!
最佳答案
如 coffeescript documentation 所述:
-j, --join [FILE]
Before compiling, concatenate all scripts together in the order they were passed, and write them into the specified file. Useful for building large projects.
这意味着您必须以正确的顺序传递脚本。假设classA在文件classA.coffee中,classB在文件classB.coffee中,上面的命令应该是:
coffee -w -j main.js -c -l -o lib src/classB.coffee src/classA.coffee
关于class - 如何将类之间的依赖关系管理到 coffeescript 项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14217145/