Preferred Way of Creating Singleton in CoffeeScript

I’m creating a relatively straightforward “bag-o-functions”.

In JS, whenever I want to access local helper methods that are too generic to expose, I generally do the following:

Util = new function () {
    var helper = function () {}
    this.myPublic = function () {
        // some code that uses the helper
    }
}

Is this an acceptable way to achieve the same in CoffeeScript?

@Util = class
  helper = ->
  @myPublic = ->
    # some code that uses the helper


Source: javascript

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.