Coffeescript installation

10
By www.indiesjxe.com www.indiesinc.com

Transcript of Coffeescript installation

Page 1: Coffeescript installation

By

www.indiesjxe.com

www.indiesinc.com

Page 2: Coffeescript installation

• Installation for window

• Run in CMD

• Run in Browser

Page 3: Coffeescript installation

Basic Installation For Windows

Page 4: Coffeescript installation

Basic Installation For WindowsRun In CMD

• Can JavaScript run from the command line ? May be not, but Coffee Script will change your view. With Node.js, you can now run JavaScript from the command line or as part of an executable script.

• This key feature of Node.js allows Coffee Script code to be executed on the command line, providing the runtime needed for the Coffee Script compiler (which is written in Coffee Script).

Page 5: Coffeescript installation

• The very first step is to install Node.js in your windows. You have several options for installation; you could compile the source code or run one of the installers that are available for various systems.

• Node includes the npm package manager on OS X and Windows. Choose .pkg for OS X and .msi for Windows and install node from http://nodejs.org/dist/v0.6.6/ — See http://nodejs.org/dist/ for newer versions.

• Run node -v from the command line to confirm that Node.js is installed on the same path.

Basic Installation For WindowRun In CMD

Page 6: Coffeescript installation

Installation and Test Installation with Following Command

• node --version

• coffee –version

• coffee -e "console.log 'Hello World'" # Hello World

Run this commands in your command prompt

Page 7: Coffeescript installation

How to run Coffee Script in CMD

• Running the Coffee Script compiler is as easy as entering “coffee -c”, which launches the Coffee Script read-evaluate-print-loop (REPL).

• To execute the compiler, you need to pass it a Coffee Script file that you want to compile. Create a file called cup0.coffee and paste following Source code into the file.

Example Code:

• for i in [0..5] console.log "Hello #{i}“

– Save it in filename.coffee

Page 8: Coffeescript installation

Output should Be..

Page 9: Coffeescript installation

Calculate GCD using Coffeescriptin browser

Example Code:<html><head>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script>

<script type="text/coffeescript">gcd = (a,b) -> if (b==0) then a else gcd(b, a % b)$("#button").click ->

a = $("#a").val() b = $("#b").val() $("#c").html gcd(a,b)

</script></head><body>

A: <input type="text" id="a"/><br/>B: <input type="text" id="b"/><br/><input type="button" value="Calculate GCD" id="button"/> <br/>C: <span id="c"/>

</body></html>

Required Coffee-Script .js

Page 10: Coffeescript installation

www.indiesinc.com