Devilal Dheer
Kiprosh
 What is CoffeeScript?
 Why CoffeeScript?
 Types in CoffeeScript
 Syntax
 CoffeeScript with Rails
 Advantage & Disadvantage
 CoffeeScript is just a Javascript.
 CoffeeScript is a language that compile into
javascript.
 Code compiles one-to-one into the
equivalent JS.
 There is no interpretation at run time
 Syntax take advantage of modern OO
languages like Ruby and Python
 Easy to maintain
 Easily Readable and Understandable
 Less lines of code to solve problem
 There is no semicolons and braces.
 ‘var’ is a reserved word. So no need to
declaration .
In CoffeeScripts every value has a type.
Basically There are 6 types of values:
 Number
 Strings
 Boolean (true-false, yes-no, on-off)
 Objects
 Functions
 Undefined values
 == vs ===
 Global variable leakage (missing var)
 It has been included in Rails 3.1
 Use *.coffee extension
 To change a Javascript files name to a
coffeescript, just append .coffee to the file
name
 When a CoffeeScript files is requested, It is
processed by processor provided by CoffeeScript.
 Rails 3.1, generate controller gives us a
CoffeeScript file automatically
Example:
 rails new MyCoffee
 cd MyCoffee
 rails generate controller User signup
jQuery(function() {
$("#title").show();
});
jQuery function()
$("#title").show()
jQuery ->
$("#title").show()
function becomes ->
this. becomes @
var square;
square = function(x) {
return x * x;
};
square = (x) -> x * x
var kids = {
brother: {
name: “max",
age: 11
}
};
kids =
brother:
name: “max”
age: 11
 Postfix if/unless
 Implicit returns
 String interpolations
 Its javascripts, not ruby so:
 Parentheses are not optional on functions
with no arguments
 Less code
 Compile time code check
 Compiles into pure javascripts
 Debugging is too hard
 Always has return value(*)
Coffee scripts with rails

Coffee scripts with rails

  • 1.
  • 2.
     What isCoffeeScript?  Why CoffeeScript?  Types in CoffeeScript  Syntax  CoffeeScript with Rails  Advantage & Disadvantage
  • 3.
     CoffeeScript isjust a Javascript.  CoffeeScript is a language that compile into javascript.  Code compiles one-to-one into the equivalent JS.  There is no interpretation at run time  Syntax take advantage of modern OO languages like Ruby and Python
  • 4.
     Easy tomaintain  Easily Readable and Understandable  Less lines of code to solve problem  There is no semicolons and braces.  ‘var’ is a reserved word. So no need to declaration .
  • 5.
    In CoffeeScripts everyvalue has a type. Basically There are 6 types of values:  Number  Strings  Boolean (true-false, yes-no, on-off)  Objects  Functions  Undefined values
  • 6.
     == vs===  Global variable leakage (missing var)
  • 7.
     It hasbeen included in Rails 3.1  Use *.coffee extension  To change a Javascript files name to a coffeescript, just append .coffee to the file name  When a CoffeeScript files is requested, It is processed by processor provided by CoffeeScript.  Rails 3.1, generate controller gives us a CoffeeScript file automatically Example:  rails new MyCoffee  cd MyCoffee  rails generate controller User signup
  • 8.
    jQuery(function() { $("#title").show(); }); jQuery function() $("#title").show() jQuery-> $("#title").show() function becomes -> this. becomes @
  • 9.
    var square; square =function(x) { return x * x; }; square = (x) -> x * x
  • 10.
    var kids ={ brother: { name: “max", age: 11 } }; kids = brother: name: “max” age: 11
  • 11.
     Postfix if/unless Implicit returns  String interpolations  Its javascripts, not ruby so:  Parentheses are not optional on functions with no arguments
  • 12.
     Less code Compile time code check  Compiles into pure javascripts
  • 13.
     Debugging istoo hard  Always has return value(*)