Is there a way to send CoffeeScript to the client's browser and have it compiled to JavaScript *there*?

后端 未结 3 1008
栀梦
栀梦 2020-11-29 02:03

Is there a way to send CoffeeScript to the client\'s browser and have it compiled to JavaScript there?



        
3条回答
  •  不知归路
    2020-11-29 02:42

    The answer is yes. I won't repeat @Trevor's excellent answer, but rather just provide an example of what you're thinking about:

    http://forgivingworm.wordpress.com/2010/09/27/running-coffeescript-in-browser/

    Basically you

    1. Tag your coffeescript with the text/coffeescript
    2. Include coffee-script.js after all coffeescript on the page (the compiler will evaluate and compile all coffeescript in order)

    Sample HTML below

    
      
        In-Browser test
        
        
        
      
      
        

    CoffeeScript is alive!

提交回复
热议问题