News for hackers. Stuff that matters.
Re:Module Pattern in JavaScript and CoffeeScript by natefaubion on Friday May 31, 2013 @10:40AM (#5798873)
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.
Re:Module Pattern in JavaScript and CoffeeScript by joshuacc on Friday May 31, 2013 @10:55AM (#5798950)
And you don't even need to use assignment. This works as well:

    do ->
      # module body
Re:Module Pattern in JavaScript and CoffeeScript by catshirt on Friday May 31, 2013 @12:12PM (#5799451)
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.

Re:Module Pattern in JavaScript and CoffeeScript by dmix on Friday May 31, 2013 @12:18PM (#5799491)
Interesting, I looked this up.

> CoffeeScript provides the do keyword, which immediately invokes a passed function, forwarding any arguments.

Apparently in April 2012 they updated the code to make it simulate namespacing.

> A tweak to the semantics of do, which can now be used to more easily simulate a namespace: do (x = 1, y = 2) -> ...

Re:Module Pattern in JavaScript and CoffeeScript by heidar on Friday May 31, 2013 @11:12AM (#5799064)
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?
Re:Module Pattern in JavaScript and CoffeeScript by bti on Friday May 31, 2013 @11:29AM (#5799172)
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".
Re:Module Pattern in JavaScript and CoffeeScript by natefaubion on Friday May 31, 2013 @11:22AM (#5799126)
There aren't native modules in JS (though they are coming in ES6). The module pattern is a way of having private scope by wrapping everything in a closure. So yes, the module pattern just creates a closure and returns an object (or assigns to global scope) with its public members.
Re:Module Pattern in JavaScript and CoffeeScript by drinchev on Saturday June 01, 2013 @03:53AM (#5803187)
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();
Re:Module Pattern in JavaScript and CoffeeScript by _volkan_ on Friday May 31, 2013 @03:53PM (#5800981)
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?
Re:Module Pattern in JavaScript and CoffeeScript by nthitz on Friday May 31, 2013 @12:09PM (#5799419)
This is pretty similar to what I've been doing. Does anyone have any thoughts on using CoffeeScript with RequireJS?
Re:Module Pattern in JavaScript and CoffeeScript by antonwinter on Friday May 31, 2013 @11:14AM (#5799078)
very clear tutorial. thumbs up
Re:Module Pattern in JavaScript and CoffeeScript by wittysense on Friday May 31, 2013 @11:04AM (#5799019)
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/t...