2015-07-19 23 views
1

我正在創建一個相對簡單的「bag-o-functions」。在CoffeeScript中創建單例的首選方法

在JS,每當我想訪問本地助手方法,這些方法過於籠統揭露,我一般做到以下幾點:

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

這是實現的CoffeeScript同一種可接受的方式?

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

回答

0

你可以像下面這樣做

Util = new (-> 
    helper = -> 
    @myPublic = -> 
    # some code that uses the helper 
    return 
    return 
) 
相關問題