Example of using Coffeescript classes and RequireJS (or Curljs or similar) for client side browser library

前端 未结 3 1179
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 17:38

We want to develop a browser (client side only) library using Coffeescript, and in particular, we tend to use the \"class\" capability of Coffeescript quite a bit, in addition t

3条回答
  •  囚心锁ツ
    2021-01-30 18:29

    I haven't actually used this technique yet, but:

    The only thing to keep in mind here is that CoffeeScript statements are also return values when they are last in a function. So, basically, the following code:

    define [], () ->
      class Main
    

    translates to:

    define([], function() {
      var Main;
      return Main = (function() {
    
        function Main() {}
    
        return Main;
    
      })();
    });
    

    and that should work as expected (I see no reason why it wouldn't based on the compiled JavaScript).

    For managing code base, I believe the CS plugin should come in handy. It's maintained by James Burke himself, and supports building of CoffeeScript projects the same way JavaScript projects are built.

提交回复
热议问题