SlideShare una empresa de Scribd logo
1 de 81
CoffeeScript
                        a better way to write javascrip




photo by SixRevisions
You can get this slide on
www.eddie.com.tw/slides
Who am I ?
I’m a Flash guy.




photo by JD Hancock
a.k.a Eddie or Aquarianboy
 Live and work in Taipei, Taiwan.
 Serving in my own little tiny company.
 Flash / AS3 / Ruby / Rails / Python programming for living.
 A little bit Objective-C for personal inerests.
 Technical Education and Consulant.
 PTT Flash BM (since 2007/4).
 Adobe Certificaed Flash Developer (Since 2006/7).
 Linux Professional Institue Certification (Since 2005/3).
                                                               photo by Eddie
or just google me with keyword "   "
JavaScript
                becomes
                hugely
                popular.
                9th on TIOBE, Nov 2011

photo by gr3m
JavaScript
                       seems
photo by apple apple
                       easy..
But it’s
not easy
o wrie
good
JavaScript
code.
             photo by Marcus Q
Today, I won't ell you..
   You should give up the way you did
I am going o ell you..
Maybe you have a better way to do with this
CoffeeScript
We’re not
                      alking
                   about this
                      kind of
                      coffee.
photo by Nick Humphries
WTF?
CoffeeScript is JavaScript
     just written with different syntax
..exposes the good parats of
JavaScript in a simple way.
Synax borrowed from
  Python and Ruby.
      I love Python & Ruby
..and will be compiled ino
JavaScript code.
..that doesn’t mean you can
have no knowledge about
JavaScript.
CoffeeScript is not used
 o replace JavaScript.
Let’s get our feet wet!
photo by jlhopes
Insall
          photo by Daniel Dionne
Requirements
You need o insall some software first..

    Node.js
     >   git clone git://github.com/joyent/node.git
     >   cd node
     >   ./configure
     >   make
     >   sudo make insall
Requirements
You need o insall some software first..

    NPM, the “node package manager”
     > curl http://npmjs.org/insall.sh | sh
Insall CoffeeScript

  CoffeeScript
   > npm insall coffee-script
   > coffee -v
   CoffeeScript version 1.1.3




     http://blog.eddie.com.w/2011/08/03/install-coffeescrip/
How o use


        photo by roboppy
Usage
Compile *.coffee ino *.js

    Compile
     > coffee --wach --compile app.coffee




  http://blog.eddie.com.w/2011/08/03/how-to-use-coffeescrip-compiler/
Synax
         photo by zigazou76
}
        }
    }
}
No { }
indenations rule!
    whitespace matters!
( ) is not necessary.
No trailing semicolon.
Return is not necessary.
      everything is an expression
No { }, (), and ;
 if(age > 20){
     voe();
 }


                    // javascript


 if age > 20
     voe()



                    # coffeescript
Variable & Function
Variable
You don’t have o declare it before using it.

 lang = ["php", "python", "perl", "ruby"]
 name = "Eddie"


                                                # coffeescript


 var lang, name;
 lang = ["php", "python", "perl", "ruby"];
 name = "Eddie";


                                                // javascript
Function
say_hello = (guest1, guest2 = "Nayumi") ->
   "Hello #{guest1} and #{guest2}"

say_hello "Eddie"

                                                  # coffeescript


var say_hello;
say_hello = function(guest1, guest2) {
   if (guest2 == null) {
       guest2 = "Nayumi";
   }
   return "Hello " + guest1 + " and " + guest2;
};
say_hello("Eddie");
                                                  // javascript
Array
Array
heroes = [
   'Spider Man',
   'Capain America',
   'X-men',
   'Iron Man'
]

students = [1..10]
eachers = [1...10]                                                # coffeescript


var heroes, students, eachers;
heroes = ['Spider Man', 'Capain America', 'X-men', 'Iron Man'];
students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
eachers = [1, 2, 3, 4, 5, 6, 7, 8, 9];

                                                                   // javascript
Array
heroes[0..2]
heroes[1..2] = ["Batman", "ThunderCat"]




                                                               # coffeescript


 heroes.slice(0, 3);

 var _ref;
 [].splice.apply(heroes, [1, 2].concat(_ref = ["Batman", "ThunderCat"])), _ref;


                                                                // javascript
Object
Object
eddie = { name: "Eddie Kao", age: 18, speciality: "eat" }




                                                      # coffeescript


var eddie;
eddie = {
   name: "Eddie Kao",
   age: 18,
   speciality: "eat"
};
                                                       // javascript
Object
eddie =                   var eddie;
 name: "Eddie Kao"        eddie = {
 age: 18                     name: "Eddie Kao",
 lovers:                     age: 18,
   nayumi:                   lovers: {
    name: "Nayumi Hung"        nayumi: {
    age: 18                       name: "Nayumi Hung",
   mary:                          age: 18
    name: "Mary Bloody"        },
    age: 20                    mary: {
                                  name: "Mary Bloody",
                                  age: 20
                               }
                             }
                          };


# coffeescript                               // javascript
Loop
Loop
alert i for i in [1..10]          var i, _sep;
                                  for (i = 1; i <= 10; i++) {
                                    alert(i);
                                  }
alert i for i in [1..10] when i   for (i = 1; i <= 10; i++) {
% 2 == 0                            if (i % 2 === 0) {
                                      alert(i);
                                    }
                                  }
alert i for i in [1..10] by 2     for (i = 1, _sep = 2; i <= 10; i +=
                                  _sep) {
                                    alert(i);
                                  }
alert i * 2 for i in [1..10]      for (i = 1; i <= 10; i++) {
                                    alert(i * 2);
# coffeescript                    }                      // javascript
Modifier
Modifier
You can put "if", "unless", "while", "until" behind

 if (age > 20) {
   voe();
 }



                                                      // javascript


 voe() if age > 20



                                                      # coffeescript
Synactic Sugar
Synactic Sugar
wrie more readable code by using synactic sugar.
# coffeescript                                // javascript

  is                                               ===
  isnt                                              !==
  true, on, yes                                   true
  false, off, no                                  false
  not                                                  !
  and                                              &&
  or                                                 ||
  unless                                        if not
  until                                      while not
  of                                                 in
Synactic Sugar
alert "I can't see anything" if light is off

alert "It's impossible!" if eddie isnt handsome

if girl is not single
    alert "Don't Touch! Be Careful!"
                                                  # coffeescript

if (light === false) {
     alert("I can't see anything");
}
if (eddie !== handsome) {
     alert("It's impossible!");
}
if (girl === !single) {
     alert("Don't Touch! Be Careful!");
}                                                 // javascript
Synactic Sugar

 if (Answer === true) {
     alert("I'll marry you!");
 }

                                      // javascript



    alert "I'll marry you!" if Answer is yes
Synactic Sugar
age ?= 18
                                                   # coffeescript


if (typeof age !== "undefined" && age !== null) {
     age;
} else {
     age = 18;
};
                                                   // javascript
Raw JavaScript
If you still prefer the original way
Raw JavaScript
say_hello = `function(name){
   return "Hello, " + name
}`


                               # coffeescript


var say_hello;
say_hello = function(name){
   return "Hello, " + name
};



                               // javascript
OOP
OOP - new
class Animal
   construcor: (name, age) ->
       this.name = name
       this.age = age

animal = new Animal("eddie", 18)
alert animal                        # coffeescript

var Animal, animal;
Animal = (function() {
   function Animal(name, age) {
      this.name = name;
      this.age = age;
   }
   return Animal;
})();
animal = new Animal("eddie", 18);
alert(animal);                      // javascript
OOP - method
class Animal
   construcor: (@name, @age) ->

   say_hello: (something) ->
      console.log "Hello, #{something}"

animal = new Animal("eddie", 18)
animal.say_hello("CoffeeScript")                        # coffeescript

var Animal, animal;
Animal = (function() {
   function Animal(name, age) {
      this.name = name;
      this.age = age;
   }
   Animal.prootype.say_hello = function(something) {
      return console.log("Hello, " + something);
   };
   return Animal;
})();
animal = new Animal("eddie", 18);                       // javascript
animal.say_hello("CoffeeScript");
OOP - inheriance
class Animal
   construcor: (@name, @age) ->
   say_hello: (something) ->
       alert "Hello, #{something}"

class Human exends Animal
   walk: ->
       alert "I can walk with my foots!"

eddie = new Human("eddie", 18)
eddie.say_hello "CoffeeScript"
eddie.walk()
                                           # coffeescript



TL; DR                                     // javascript
References
Websies:
 http://jashkenas.github.com/coffee-scrip/
 http://blog.eddie.com.w/category/coffeescrip/


Book:
 http://pragprog.com/book/tbcoffee/coffeescrip
the good parts
photo by Steve Ganz
                               I love
I Love..




              Coding Style
           I love Python & Ruby, of course :)
I Love..




           Indenation!
I Love..




    Anonymous function
     No global function and variable by default
I Love..




     String Inerpolation
       sorry, but string building really sucks :)
I Love..




     List Comprehension
I Love..




           Synactic Sugar
I Love..




    English-like grammar
  alert "of course it is!" if PHPConf is awesome
I Love..




  Comparison & Equality
           "true" == true // true
           "true" === true // false
I Love..



    Works with other JS
     frameworks well.
           Because it’s just JavaScrip
I Love..




           Compilation
            JSLint Approved
What else?
CoffeeScript compiler is
writen in CoffeeScript.
Tianium Mobile



http://blog.eddie.com.w/2011/08/03/using-coffeescrip-in-titanium-studio/
photo by Andrew
Immature?
            photo by theseanster93
Performance?
photo by chr1sl4i           photo by theseanster93
CoffeeScript Means Giving
Up on JavaScript?
Learn JavaScript, and Use
CoffeeScript.
Any Question?   photo by jamuraa
Conacts
     Websie    http://www.eddie.com.tw
     Blog       http://blog.eddie.com.tw
     Plurk      http://www.plurk.com/aquarianboy
     Facebook   http://www.facebook.com/eddiekao
     Google Plus http://www.eddie.com.tw/+
     Twiter    https://twiter.com/#!/eddiekao
     Email      eddie@digik.com.tw
     Mobile     +886-928-617-687




                                                   photo by Eddie

Más contenido relacionado

La actualidad más candente

5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScriptTodd Anglin
 
Adding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxAdding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxJeff Strauss
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To ClosureRobert Nyman
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.jsBert Wijnants
 
JavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDayJavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDayRobert Nyman
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsJarod Ferguson
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptMohd Saeed
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5arajivmordani
 
Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009pratiknaik
 
JavaScript and HTML5 - Brave New World (revised)
JavaScript and HTML5 - Brave New World (revised)JavaScript and HTML5 - Brave New World (revised)
JavaScript and HTML5 - Brave New World (revised)Robert Nyman
 
CoffeeScript in 5mins
CoffeeScript in 5minsCoffeeScript in 5mins
CoffeeScript in 5minsMasakuni Kato
 
Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitRebecca Murphey
 
DSLs Internas e Ruby
DSLs Internas e RubyDSLs Internas e Ruby
DSLs Internas e RubyFabio Kung
 
Backbone.js and friends
Backbone.js and friendsBackbone.js and friends
Backbone.js and friendsGood Robot
 
Javascript - The Good, the Bad and the Ugly
Javascript - The Good, the Bad and the UglyJavascript - The Good, the Bad and the Ugly
Javascript - The Good, the Bad and the UglyThorsten Suckow-Homberg
 
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of ChocolatesJavaScript - Like a Box of Chocolates
JavaScript - Like a Box of ChocolatesRobert Nyman
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJSSylvain Zimmer
 

La actualidad más candente (20)

5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
 
Adding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxAdding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer Toolbox
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
 
Ruby
RubyRuby
Ruby
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
 
JavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDayJavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDay
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascript
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009
 
JavaScript and HTML5 - Brave New World (revised)
JavaScript and HTML5 - Brave New World (revised)JavaScript and HTML5 - Brave New World (revised)
JavaScript and HTML5 - Brave New World (revised)
 
CoffeeScript in 5mins
CoffeeScript in 5minsCoffeeScript in 5mins
CoffeeScript in 5mins
 
Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development Toolkit
 
DSLs Internas e Ruby
DSLs Internas e RubyDSLs Internas e Ruby
DSLs Internas e Ruby
 
Backbone.js and friends
Backbone.js and friendsBackbone.js and friends
Backbone.js and friends
 
Javascript - The Good, the Bad and the Ugly
Javascript - The Good, the Bad and the UglyJavascript - The Good, the Bad and the Ugly
Javascript - The Good, the Bad and the Ugly
 
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of ChocolatesJavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJS
 

Destacado

AS3 Better Practices
AS3 Better PracticesAS3 Better Practices
AS3 Better PracticesEddie Kao
 
Code Reading
Code ReadingCode Reading
Code ReadingEddie Kao
 
Forumwarz and RJS: A Love/Hate Affair
Forumwarz and RJS: A Love/Hate AffairForumwarz and RJS: A Love/Hate Affair
Forumwarz and RJS: A Love/Hate Affairguest06ed72
 
Flash Ecosystem and Open Source
Flash Ecosystem and Open SourceFlash Ecosystem and Open Source
Flash Ecosystem and Open SourceEddie Kao
 
Agenda 6è b setmana 02-gener-curs 16-17
Agenda 6è b setmana 02-gener-curs 16-17Agenda 6è b setmana 02-gener-curs 16-17
Agenda 6è b setmana 02-gener-curs 16-176sise
 

Destacado (6)

AS3 Better Practices
AS3 Better PracticesAS3 Better Practices
AS3 Better Practices
 
Code Reading
Code ReadingCode Reading
Code Reading
 
Forumwarz and RJS: A Love/Hate Affair
Forumwarz and RJS: A Love/Hate AffairForumwarz and RJS: A Love/Hate Affair
Forumwarz and RJS: A Love/Hate Affair
 
Flash Ecosystem and Open Source
Flash Ecosystem and Open SourceFlash Ecosystem and Open Source
Flash Ecosystem and Open Source
 
測試
測試測試
測試
 
Agenda 6è b setmana 02-gener-curs 16-17
Agenda 6è b setmana 02-gener-curs 16-17Agenda 6è b setmana 02-gener-curs 16-17
Agenda 6è b setmana 02-gener-curs 16-17
 

Similar a CoffeeScript

JavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldJavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldRobert Nyman
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScriptNone
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love RubyBen Scheirman
 
CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better! CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better! Jack Franklin
 
Happy Programming with CoffeeScript
Happy Programming with CoffeeScriptHappy Programming with CoffeeScript
Happy Programming with CoffeeScriptEddie Kao
 
WappZapp & Appcelerator Titanium
WappZapp & Appcelerator TitaniumWappZapp & Appcelerator Titanium
WappZapp & Appcelerator TitaniumWienke Giezeman
 
bol.com Partner event 2013 - Presentatie Wienke Giezeman
bol.com Partner event 2013 - Presentatie Wienke Giezemanbol.com Partner event 2013 - Presentatie Wienke Giezeman
bol.com Partner event 2013 - Presentatie Wienke Giezemanbolcompp
 
JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)jeresig
 
CoffeeScript - en introduksjon
CoffeeScript - en introduksjonCoffeeScript - en introduksjon
CoffeeScript - en introduksjonKamikaze Media AS
 
Node.js for PHP developers
Node.js for PHP developersNode.js for PHP developers
Node.js for PHP developersAndrew Eddie
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRaimonds Simanovskis
 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsIgnacio Martín
 
Coffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotesCoffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotesBrandon Satrom
 

Similar a CoffeeScript (20)

JavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldJavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New World
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better! CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better!
 
Happy Programming with CoffeeScript
Happy Programming with CoffeeScriptHappy Programming with CoffeeScript
Happy Programming with CoffeeScript
 
WappZapp & Appcelerator Titanium
WappZapp & Appcelerator TitaniumWappZapp & Appcelerator Titanium
WappZapp & Appcelerator Titanium
 
bol.com Partner event 2013 - Presentatie Wienke Giezeman
bol.com Partner event 2013 - Presentatie Wienke Giezemanbol.com Partner event 2013 - Presentatie Wienke Giezeman
bol.com Partner event 2013 - Presentatie Wienke Giezeman
 
JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)
 
CoffeeScript - en introduksjon
CoffeeScript - en introduksjonCoffeeScript - en introduksjon
CoffeeScript - en introduksjon
 
Node.js for PHP developers
Node.js for PHP developersNode.js for PHP developers
Node.js for PHP developers
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worlds
 
Coffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotesCoffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotes
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Scala.js
Scala.jsScala.js
Scala.js
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Coffee script
Coffee scriptCoffee script
Coffee script
 
Javascript The Good Parts
Javascript The Good PartsJavascript The Good Parts
Javascript The Good Parts
 

Más de Eddie Kao

Rails girls in Taipei
Rails girls in TaipeiRails girls in Taipei
Rails girls in TaipeiEddie Kao
 
Rails Girls in Taipei
Rails Girls in TaipeiRails Girls in Taipei
Rails Girls in TaipeiEddie Kao
 
Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - BasicEddie Kao
 
iOS app development and Open Source
iOS app development and Open SourceiOS app development and Open Source
iOS app development and Open SourceEddie Kao
 
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-CEddie Kao
 
CreateJS - from Flash to Javascript
CreateJS - from Flash to JavascriptCreateJS - from Flash to Javascript
CreateJS - from Flash to JavascriptEddie Kao
 
May the source_be_with_you
May the source_be_with_youMay the source_be_with_you
May the source_be_with_youEddie Kao
 
Why I use Vim
Why I use VimWhy I use Vim
Why I use VimEddie Kao
 
There is something about Event
There is something about EventThere is something about Event
There is something about EventEddie Kao
 
Ruby without rails
Ruby without railsRuby without rails
Ruby without railsEddie Kao
 
3rd AS Study Group
3rd AS Study Group3rd AS Study Group
3rd AS Study GroupEddie Kao
 
iOS Game Development with Cocos2d
iOS Game Development with Cocos2diOS Game Development with Cocos2d
iOS Game Development with Cocos2dEddie Kao
 
AS3讀書會(行前準備)
AS3讀書會(行前準備)AS3讀書會(行前準備)
AS3讀書會(行前準備)Eddie Kao
 
Misunderstanding about flash
Misunderstanding about flashMisunderstanding about flash
Misunderstanding about flashEddie Kao
 
Refactoring in AS3
Refactoring in AS3Refactoring in AS3
Refactoring in AS3Eddie Kao
 

Más de Eddie Kao (19)

Rails girls in Taipei
Rails girls in TaipeiRails girls in Taipei
Rails girls in Taipei
 
Rails Girls in Taipei
Rails Girls in TaipeiRails Girls in Taipei
Rails Girls in Taipei
 
Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - Basic
 
iOS app development and Open Source
iOS app development and Open SourceiOS app development and Open Source
iOS app development and Open Source
 
Vim
VimVim
Vim
 
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-C
 
CreateJS - from Flash to Javascript
CreateJS - from Flash to JavascriptCreateJS - from Flash to Javascript
CreateJS - from Flash to Javascript
 
May the source_be_with_you
May the source_be_with_youMay the source_be_with_you
May the source_be_with_you
 
Why I use Vim
Why I use VimWhy I use Vim
Why I use Vim
 
There is something about Event
There is something about EventThere is something about Event
There is something about Event
 
Ruby without rails
Ruby without railsRuby without rails
Ruby without rails
 
API Design
API DesignAPI Design
API Design
 
3rd AS Study Group
3rd AS Study Group3rd AS Study Group
3rd AS Study Group
 
iOS Game Development with Cocos2d
iOS Game Development with Cocos2diOS Game Development with Cocos2d
iOS Game Development with Cocos2d
 
AS3讀書會(行前準備)
AS3讀書會(行前準備)AS3讀書會(行前準備)
AS3讀書會(行前準備)
 
AMF
AMFAMF
AMF
 
Misunderstanding about flash
Misunderstanding about flashMisunderstanding about flash
Misunderstanding about flash
 
Refactoring in AS3
Refactoring in AS3Refactoring in AS3
Refactoring in AS3
 
Test
TestTest
Test
 

Último

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 

Último (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 

CoffeeScript

  • 1. CoffeeScript a better way to write javascrip photo by SixRevisions
  • 2.
  • 3. You can get this slide on www.eddie.com.tw/slides
  • 5. I’m a Flash guy. photo by JD Hancock
  • 6. a.k.a Eddie or Aquarianboy Live and work in Taipei, Taiwan. Serving in my own little tiny company. Flash / AS3 / Ruby / Rails / Python programming for living. A little bit Objective-C for personal inerests. Technical Education and Consulant. PTT Flash BM (since 2007/4). Adobe Certificaed Flash Developer (Since 2006/7). Linux Professional Institue Certification (Since 2005/3). photo by Eddie
  • 7. or just google me with keyword " "
  • 8. JavaScript becomes hugely popular. 9th on TIOBE, Nov 2011 photo by gr3m
  • 9. JavaScript seems photo by apple apple easy..
  • 10. But it’s not easy o wrie good JavaScript code. photo by Marcus Q
  • 11. Today, I won't ell you.. You should give up the way you did
  • 12. I am going o ell you.. Maybe you have a better way to do with this
  • 14. We’re not alking about this kind of coffee. photo by Nick Humphries
  • 15. WTF?
  • 16. CoffeeScript is JavaScript just written with different syntax
  • 17. ..exposes the good parats of JavaScript in a simple way.
  • 18. Synax borrowed from Python and Ruby. I love Python & Ruby
  • 19. ..and will be compiled ino JavaScript code.
  • 20. ..that doesn’t mean you can have no knowledge about JavaScript.
  • 21. CoffeeScript is not used o replace JavaScript.
  • 22. Let’s get our feet wet! photo by jlhopes
  • 23. Insall photo by Daniel Dionne
  • 24. Requirements You need o insall some software first.. Node.js > git clone git://github.com/joyent/node.git > cd node > ./configure > make > sudo make insall
  • 25. Requirements You need o insall some software first.. NPM, the “node package manager” > curl http://npmjs.org/insall.sh | sh
  • 26. Insall CoffeeScript CoffeeScript > npm insall coffee-script > coffee -v CoffeeScript version 1.1.3 http://blog.eddie.com.w/2011/08/03/install-coffeescrip/
  • 27. How o use photo by roboppy
  • 28. Usage Compile *.coffee ino *.js Compile > coffee --wach --compile app.coffee http://blog.eddie.com.w/2011/08/03/how-to-use-coffeescrip-compiler/
  • 29. Synax photo by zigazou76
  • 30. } } } }
  • 31. No { } indenations rule! whitespace matters!
  • 32. ( ) is not necessary.
  • 34. Return is not necessary. everything is an expression
  • 35. No { }, (), and ; if(age > 20){ voe(); } // javascript if age > 20 voe() # coffeescript
  • 37. Variable You don’t have o declare it before using it. lang = ["php", "python", "perl", "ruby"] name = "Eddie" # coffeescript var lang, name; lang = ["php", "python", "perl", "ruby"]; name = "Eddie"; // javascript
  • 38. Function say_hello = (guest1, guest2 = "Nayumi") -> "Hello #{guest1} and #{guest2}" say_hello "Eddie" # coffeescript var say_hello; say_hello = function(guest1, guest2) { if (guest2 == null) { guest2 = "Nayumi"; } return "Hello " + guest1 + " and " + guest2; }; say_hello("Eddie"); // javascript
  • 39. Array
  • 40. Array heroes = [ 'Spider Man', 'Capain America', 'X-men', 'Iron Man' ] students = [1..10] eachers = [1...10] # coffeescript var heroes, students, eachers; heroes = ['Spider Man', 'Capain America', 'X-men', 'Iron Man']; students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; eachers = [1, 2, 3, 4, 5, 6, 7, 8, 9]; // javascript
  • 41. Array heroes[0..2] heroes[1..2] = ["Batman", "ThunderCat"] # coffeescript heroes.slice(0, 3); var _ref; [].splice.apply(heroes, [1, 2].concat(_ref = ["Batman", "ThunderCat"])), _ref; // javascript
  • 43. Object eddie = { name: "Eddie Kao", age: 18, speciality: "eat" } # coffeescript var eddie; eddie = { name: "Eddie Kao", age: 18, speciality: "eat" }; // javascript
  • 44. Object eddie = var eddie; name: "Eddie Kao" eddie = { age: 18 name: "Eddie Kao", lovers: age: 18, nayumi: lovers: { name: "Nayumi Hung" nayumi: { age: 18 name: "Nayumi Hung", mary: age: 18 name: "Mary Bloody" }, age: 20 mary: { name: "Mary Bloody", age: 20 } } }; # coffeescript // javascript
  • 45. Loop
  • 46. Loop alert i for i in [1..10] var i, _sep; for (i = 1; i <= 10; i++) { alert(i); } alert i for i in [1..10] when i for (i = 1; i <= 10; i++) { % 2 == 0 if (i % 2 === 0) { alert(i); } } alert i for i in [1..10] by 2 for (i = 1, _sep = 2; i <= 10; i += _sep) { alert(i); } alert i * 2 for i in [1..10] for (i = 1; i <= 10; i++) { alert(i * 2); # coffeescript } // javascript
  • 48. Modifier You can put "if", "unless", "while", "until" behind if (age > 20) { voe(); } // javascript voe() if age > 20 # coffeescript
  • 50. Synactic Sugar wrie more readable code by using synactic sugar. # coffeescript // javascript is === isnt !== true, on, yes true false, off, no false not ! and && or || unless if not until while not of in
  • 51. Synactic Sugar alert "I can't see anything" if light is off alert "It's impossible!" if eddie isnt handsome if girl is not single alert "Don't Touch! Be Careful!" # coffeescript if (light === false) { alert("I can't see anything"); } if (eddie !== handsome) { alert("It's impossible!"); } if (girl === !single) { alert("Don't Touch! Be Careful!"); } // javascript
  • 52. Synactic Sugar if (Answer === true) { alert("I'll marry you!"); } // javascript alert "I'll marry you!" if Answer is yes
  • 53. Synactic Sugar age ?= 18 # coffeescript if (typeof age !== "undefined" && age !== null) { age; } else { age = 18; }; // javascript
  • 54. Raw JavaScript If you still prefer the original way
  • 55. Raw JavaScript say_hello = `function(name){ return "Hello, " + name }` # coffeescript var say_hello; say_hello = function(name){ return "Hello, " + name }; // javascript
  • 56. OOP
  • 57. OOP - new class Animal construcor: (name, age) -> this.name = name this.age = age animal = new Animal("eddie", 18) alert animal # coffeescript var Animal, animal; Animal = (function() { function Animal(name, age) { this.name = name; this.age = age; } return Animal; })(); animal = new Animal("eddie", 18); alert(animal); // javascript
  • 58. OOP - method class Animal construcor: (@name, @age) -> say_hello: (something) -> console.log "Hello, #{something}" animal = new Animal("eddie", 18) animal.say_hello("CoffeeScript") # coffeescript var Animal, animal; Animal = (function() { function Animal(name, age) { this.name = name; this.age = age; } Animal.prootype.say_hello = function(something) { return console.log("Hello, " + something); }; return Animal; })(); animal = new Animal("eddie", 18); // javascript animal.say_hello("CoffeeScript");
  • 59. OOP - inheriance class Animal construcor: (@name, @age) -> say_hello: (something) -> alert "Hello, #{something}" class Human exends Animal walk: -> alert "I can walk with my foots!" eddie = new Human("eddie", 18) eddie.say_hello "CoffeeScript" eddie.walk() # coffeescript TL; DR // javascript
  • 61. the good parts photo by Steve Ganz I love
  • 62. I Love.. Coding Style I love Python & Ruby, of course :)
  • 63. I Love.. Indenation!
  • 64. I Love.. Anonymous function No global function and variable by default
  • 65. I Love.. String Inerpolation sorry, but string building really sucks :)
  • 66. I Love.. List Comprehension
  • 67. I Love.. Synactic Sugar
  • 68. I Love.. English-like grammar alert "of course it is!" if PHPConf is awesome
  • 69. I Love.. Comparison & Equality "true" == true // true "true" === true // false
  • 70. I Love.. Works with other JS frameworks well. Because it’s just JavaScrip
  • 71. I Love.. Compilation JSLint Approved
  • 76. Immature? photo by theseanster93
  • 77. Performance? photo by chr1sl4i photo by theseanster93
  • 79. Learn JavaScript, and Use CoffeeScript.
  • 80. Any Question? photo by jamuraa
  • 81. Conacts Websie http://www.eddie.com.tw Blog http://blog.eddie.com.tw Plurk http://www.plurk.com/aquarianboy Facebook http://www.facebook.com/eddiekao Google Plus http://www.eddie.com.tw/+ Twiter https://twiter.com/#!/eddiekao Email eddie@digik.com.tw Mobile +886-928-617-687 photo by Eddie