3 ms·
sorry for being a n00b but what's the goal of the "class @User" syntax? I have a cursory knowledge of CS and I'd assume that gets desugared to something like
by riffraff 15y ago
sorry for being a n00b but what's the goal of the "class @User" syntax?
I have a cursory knowledge of CS and I'd assume that gets desugared to something like
this.User = ...
but what use does it have?
- ryanf 15y agoCoffeeScript wraps its output in an anonymous function, so to create a global var you have to explicitly assign it as "window.varname" or, at the top level, "this.varname".
- riffraff 15y agoah that's interesting thanks for the explanation
- jonutzz 15y agoI have the same question!
- nixme 15y agoBy default, CS compiles with a closure per file to prevent local variables from leaking to the global scope. So the purpose is to ensure the class is exported. If you put the following in a user.coffee file: class User it would compile to: (function() { User = (function() { function User() {} return User; })(); }).call(this); while class @User would compile to: (function() { this.User = (function() { function User() {} return User; })(); }).call(this); ensuring that User is available from any file (since the top-level this === window in the browser).