

Module Pattern in JavaScript and CoffeeScript - Croaky
http://robots.thoughtbot.com/post/51801869159/module-pattern-in-javascript-and-coffeescript

======
natefaubion
A cleaner way of doing the immediately-invoking function in CS is to use a
`do` statement.

    
    
        MyModule = do ->
          # module body
    

No need for any parens.

~~~
joshuacc
And you don't even need to use assignment. This works as well:

    
    
        do ->
          # module body

~~~
catshirt
you don't need to assign it to something, unless you need to assign it to
something.

sounds like op was specifically referencing to parens for execution.

------
heidar
I have only just started learning the details of JavaScript. While reading
JavaScript: The Good Parts I found myself asking the question what the
difference between a module and a closure is. As far as I can tell they are
the same thing. Is that correct or am I missing something?

~~~
bti
A module is a design pattern and a closure is a language construct. A module
(in the context of the "module pattern") is a closure but all closures are not
"modules".

------
drinchev
Well I really prefer creating classes and AMD modules for almost everything.
Using CoffeeScript this is just a couple of rows:

    
    
        class Calculator
    
            prettyText = "Answer is: "
            printResult = (result) -> console.log result
      
            add: (addedOne, addedTwo) => 
               sum = addedOne + addedTwo
               printResult prettyText + sum
    
        calculator = new Calculator();

------
_volkan_
Nice article....Is there a reason for having a separate return within each
method? How about returning all of the methods with a single return?

------
nthitz
This is pretty similar to what I've been doing. Does anyone have any thoughts
on using CoffeeScript with RequireJS?

------
antonwinter
very clear tutorial. thumbs up

------
wittysense
I've been sub-namespacing conventions of MVCs, too.

    
    
        new GlobalNS.App.MicroViews.TableRow extends Backbone.View
        new GlobalNS.App.Models.TableCell extends Backbone.View
        ...
    

Essentially you can namespace to Babylon from existing conventions and build
"interaction models" (complex namespaces) for standard digital content types
like "lists", etc., from say <http://pea.rs>

JS and Hypermedia have always been in harmony. Other boring ideas:
[https://github.com/nerdfiles/nerdfiles_net_dev/blob/master/t...](https://github.com/nerdfiles/nerdfiles_net_dev/blob/master/themes/nerdfiles_net_dev/_assets/css/compass/sass/schema.scss),
[https://github.com/nerdfiles/nerdfiles_net_dev/blob/master/t...](https://github.com/nerdfiles/nerdfiles_net_dev/blob/master/themes/nerdfiles_net_dev/_assets/css/compass/sass/chaining.scss)

