Download - Coffee script final
By:Priyanka zope
About CoffeeScript
• The Golden Rule:o "Its just JavaScript"
• One-to-One Compilage into
equivalent JavaScript • Runs as fast or faster than
equivalent JavaScript
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
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>
VariablesFunctionsArraysConditional OperatorSwitch Statment
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)
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
Array
Arrays can use whitespace instead of comma separators, although the square brackets ([]) are still required.
array1 = [1, 2, 3]
array2 = [ 1
2
3
]
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
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"