Global classes with Meteor >0.6.0 and CoffeeScript -
since release of meteor 0.6.0 , addition of file-level javascript variable scoping, i'm facing issue using coffeescript classes, each of them being defined in own respective file.
foo.coffee:
class foo ...
subfoo.coffee:
class subfoo extends foo ...
as expected, , because of changes introduced in meteor 0.6.0, i'm getting following error:
referenceerror: foo not defined
here's question: how should 1 handle class definitions across files coffeescript , meteor >0.6.0? ideally: there convenient way not modify way classes defined in order make sure these definitions (and core parts of application) not meteor-dependent?
as noted in coffeescript section of docs:
global variables can set in coffeescript using (or coffeescript's @ shorthand)
as turns out, coffeescript classes can defined like:
class @foo
which compiles to:
this.foo = (function() { function foo() {} return foo; })();
assuming foo.coffee
loaded before subfoo.coffee
can do:
class @subfoo extends foo
assuming, of course, subfoo
needs be assigned global scope. it's worth mentioning you'll need expose collections in similar way. example:
@players = new meteor.collection 'players'
Comments
Post a Comment