Coffee script final

11
By: Priyanka zope

description

 

Transcript of Coffee script final

Page 1: Coffee script final

By:Priyanka zope

Page 2: Coffee script final

About CoffeeScript

• The Golden Rule:o "Its just JavaScript"

 •  One-to-One Compilage into

equivalent JavaScript  • Runs as fast or faster than

equivalent JavaScript

Page 3: Coffee script final

The code writing and use process of CoffeeScript is simple:

Write your code in a .coffee fileCompile it into a .js fileInclude the .js file in your web page/s like you would any other JavaScript file

Page 4: Coffee script final

COMMAND THROUGH

coffee --watch --compile try.coffee

DIRECT IN HTML FILE

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

type="text/javascript"></script>

Page 5: Coffee script final

VariablesFunctionsArraysConditional OperatorSwitch Statment

Page 6: Coffee script final

VariablesThere is no need to declare variable in cofeescript.

For e.g.:

**javascript**

var message;

message=“ready for some cofeescript”

alert(message);

**coffeescript**

message=“ready for some cofeescript”

alert(message)

Page 7: Coffee script final

Function• White Space Delimiter

o Semicolons ';' are useless

 • Curly braces '{}' are

unnecessaryo Solved with indents or

new lines •  Functions

o () contains parameter list

o  -> points to the body

Page 8: Coffee script final

Array

Arrays can use whitespace instead of comma separators, although the square brackets ([]) are still required.

array1 = [1, 2, 3]

 array2 = [ 1

2

3

]

 

Page 9: Coffee script final

Conditional Operators

Existential Operator• In JS, "if (var)" is close

o Fails on 0, "", and false  • In CoffeeScript

o "?" returns true if null or undefined

Page 10: Coffee script final

Switch Statements

• Typical Switch haso Switch cond:o case 1, break; case 2,

break; ...... • Switch in CoffeeScript

o Switch cond: when ... then ... else

o does not require "breaks" or "default"

Page 11: Coffee script final