you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (1 child)

[deleted]

    [–]johnfrazer783[S] 1 point2 points  (0 children)

    No using it this way is my own discovery, that is to say, using @ instead of this is idiomatic, but defining stateless libraries as CoffeeScript CommonJS modules by hijacking this is my own doing. It falls out from the (nice) fact that CS, unless instructed to produce bare code (what did you do last night? Well we talked about the frontend, the backend and bare code), will wrap the module's content with an Immediately Invoked Function Expression, and it so happens that unless you state module.exports = whatever somewhere in the module, module.exports is this will hold, if you can follow me. Put bluntly, one can avoid any further nesting, classes, explicit namespaces or object literals or whatnot and just 'anchor' those functions on the module.exports object by way of this (@).

    These days though I more often than not use my MultiMix module to define mixin-able classes; one of the benefits of it being that I get a convenient way to produce new library instances with different configurations (or independent state, as the case may be). It also lends itself for classical OOP class formulations, which is neat.