本文介绍了全局类,Meteor> 0.6.0和CoffeeScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 自从发布Meteor 0.6.0和添加文件级JavaScript变量范围,我遇到了一个使用CoffeeScript类的问题,每个类都在自己的相应文件中定义。 foo.coffee: class Foo ... subfoo.coffee: extends Foo ... 像预期的那样, .0,我得到以下错误: class @Foo 其编译为: this.Foo =(function(){ function Foo(){} return Foo; }) 假设 foo.coffee subfoo.coffee 你可以这样做: class @Subfoo extends Foo 假设 Subfoo 被分配到全局范围。还值得一提的是,您需要以类似的方式公开您的集合。例如: @Players = new Meteor.Collection玩家 pre> Since the release of Meteor 0.6.0 and the addition of file-level JavaScript variable scoping, I'm facing an issue using CoffeeScript classes, each of them being defined in its own respective file.foo.coffee:class Foo ...subfoo.coffee:class Subfoo extends Foo ...As expected, and because of the changes introduced in Meteor 0.6.0, I'm getting the following error:Here's my question: how should one handle class definitions across files with CoffeeScript and Meteor >0.6.0? Ideally: is there a convenient way not to modify too much the way classes are defined in order to make sure these definitions (and core parts of my application) are not Meteor-dependent? 解决方案 As noted in the CoffeeScript section of the docs:As it turns out, CoffeeScript classes can be defined like:class @Foowhich compiles to:this.Foo = (function() { function Foo() {} return Foo;})();Assuming that foo.coffee is loaded before subfoo.coffee you can then do:class @Subfoo extends FooAssuming, of course, that Subfoo needs be be assigned to the global scope. It's also worth mentioning that you'll need to expose your collections in a similar way. For example:@Players = new Meteor.Collection 'players' 这篇关于全局类,Meteor> 0.6.0和CoffeeScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-17 02:56
查看更多