CoffeeScript
CoffeeScript - Intro
@d_danailov
CoffeeScript : Intro
Dimitar Danailov
Senior Developer at 158ltd.com
dimityr.danailov[at]gmail.com
Github
Founder at Varna...
Topics Today
● Introduction
● Installing CoffeeScript
● Using CoffeeScript Files
● Learning the Core Functionality
● Data ...
Topics Today (2)
● Control Structures
● Loops and Comprehensions
● Scope and Context
● Stirring in Advanced Concepts
● Obj...
Installing CoffeeScript
1. Node.js
2. NPM
sudo apt-get install nodejs npm &&
3. sudo npm install -g coffee-script
4. coffe...
Using CoffeeScript Files
node.js file.js
coffee file.coffee
coffee -c file.coffee
coffee -cw file.coffee
coffee (read–eval...
Variables
Booleans :
● true/false
● yes/no
● on/off
Variables (2)
Destructuring Assignment :
theBait = 1000
theSwitch = 0
[theBait, theSwitch ] = [theSwitch, theBait]
Variables (3)
Destructuring Assignment :
weatherReport = (location) ->
# Make an Ajax request to fetch the weather...
[loc...
Comments
# Single line comment
###
Multi line comment
###
Functions
Splats :
The JavaScript arguments object is a useful way to work with functions that
accept variable numbers of ...
Operators
● JS : == / Coffee : is
● JS : != / Coffee : isnt
● JS : if (!false) / Coffee : if not false
● JS : && / Coffee ...
Condition statements
● if
● if not
● unless
● switch and when
Loops and Comprehensions
Most of the loops you'll write in CoffeeScript will be comprehensions over
arrays, objects, and r...
Loops
● for
● while
● until
● loop used with break !!!
Scope
● coffee -c --bare file.coffee
● this
● root = (export ? window)
Prototype
Classes
Regular Expressions
Similar to block strings and comments, CoffeeScript supports block regexes
— extended regular expressi...
Using CoffeeScript in the Browser
● coffee -c --watch *.coffee
● coffee -c --watch o js src/*.coffee
● http://coffeescript...
Questions ?
Dimitar Danailov
Senior Developer at 158ltd.com
dimityr.danailov[at]gmail.com
Github
Founder at VarnaIT
Senior...
Upcoming SlideShare
Loading in...5
×

Coffeescript intro

1,554

Published on

Demos created for public lecture in VarnaLab (02 October 2013)
Github Demos : https://github.com/dimitardanailov/coffeescript-intro

Agenda :
Introduction
Installing CoffeeScript
Using CoffeeScript Files

Learning the Core Functionality
Data Types
Comments and Functions
Operators
Control Structures
Loops and Comprehensions
Scope and Context

Stirring in Advanced Concepts
Object Prototypes
CoffeeScript Classes
Heregexes
Using CoffeeScript in the Browser

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,554
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Coffeescript intro

  1. 1. CoffeeScript CoffeeScript - Intro @d_danailov
  2. 2. CoffeeScript : Intro Dimitar Danailov Senior Developer at 158ltd.com dimityr.danailov[at]gmail.com Github Founder at VarnaIT Senior Developer at 158ltd.com Cleaner Code With CoffeeScript Github Code
  3. 3. Topics Today ● Introduction ● Installing CoffeeScript ● Using CoffeeScript Files ● Learning the Core Functionality ● Data Types ● Comments and Functions ● Operators
  4. 4. Topics Today (2) ● Control Structures ● Loops and Comprehensions ● Scope and Context ● Stirring in Advanced Concepts ● Object Prototypes ● CoffeeScript Classes ● Heregexes ● Using CoffeeScript in the Browser
  5. 5. Installing CoffeeScript 1. Node.js 2. NPM sudo apt-get install nodejs npm && 3. sudo npm install -g coffee-script 4. coffee -v
  6. 6. Using CoffeeScript Files node.js file.js coffee file.coffee coffee -c file.coffee coffee -cw file.coffee coffee (read–eval–print loop (REPL))
  7. 7. Variables Booleans : ● true/false ● yes/no ● on/off
  8. 8. Variables (2) Destructuring Assignment : theBait = 1000 theSwitch = 0 [theBait, theSwitch ] = [theSwitch, theBait]
  9. 9. Variables (3) Destructuring Assignment : weatherReport = (location) -> # Make an Ajax request to fetch the weather... [location, 72, "Mostly Sunny" ] [city, temp, forecast ] = weatherReport "Berkeley, CA"
  10. 10. Comments # Single line comment ### Multi line comment ###
  11. 11. Functions Splats : The JavaScript arguments object is a useful way to work with functions that accept variable numbers of arguments. CoffeeScript provides splats ..., both for function definition as well as invocation, making variable numbers of arguments a little bit more palatable. # Splats: race = (winner, runners...) -> print winner, runners
  12. 12. Operators ● JS : == / Coffee : is ● JS : != / Coffee : isnt ● JS : if (!false) / Coffee : if not false ● JS : && / Coffee : AND ● JS : || / Coffee : OR
  13. 13. Condition statements ● if ● if not ● unless ● switch and when
  14. 14. Loops and Comprehensions Most of the loops you'll write in CoffeeScript will be comprehensions over arrays, objects, and ranges. Comprehensions replace (and compile into) for loops, with optional guard clauses and the value of the current array index. Unlike for loops, array comprehensions are expressions, and can be returned and assigned.
  15. 15. Loops ● for ● while ● until ● loop used with break !!!
  16. 16. Scope ● coffee -c --bare file.coffee ● this ● root = (export ? window)
  17. 17. Prototype
  18. 18. Classes
  19. 19. Regular Expressions Similar to block strings and comments, CoffeeScript supports block regexes — extended regular expressions that ignore internal whitespace and can contain comments and interpolation. Modeled after Perl's /x modifier, CoffeeScript's block regexes are delimited by /// and go a long way towards making complex regular expressions readable.
  20. 20. Using CoffeeScript in the Browser ● coffee -c --watch *.coffee ● coffee -c --watch o js src/*.coffee ● http://coffeescript.org/#scripts
  21. 21. Questions ? Dimitar Danailov Senior Developer at 158ltd.com dimityr.danailov[at]gmail.com Github Founder at VarnaIT Senior Developer at 158ltd.com Cleaner Code With CoffeeScript Github Code
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×