Coffeescript intro

  • 1,336 views
Uploaded on

Demos created for public lecture in VarnaLab (02 October 2013) …

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

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,336
On Slideshare
0
From Embeds
0
Number of Embeds
4

Actions

Shares
Downloads
5
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. CoffeeScript CoffeeScript - Intro @d_danailov
  • 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. Topics Today ● Introduction ● Installing CoffeeScript ● Using CoffeeScript Files ● Learning the Core Functionality ● Data Types ● Comments and Functions ● Operators
  • 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. Installing CoffeeScript 1. Node.js 2. NPM sudo apt-get install nodejs npm && 3. sudo npm install -g coffee-script 4. coffee -v
  • 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. Variables Booleans : ● true/false ● yes/no ● on/off
  • 8. Variables (2) Destructuring Assignment : theBait = 1000 theSwitch = 0 [theBait, theSwitch ] = [theSwitch, theBait]
  • 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. Comments # Single line comment ### Multi line comment ###
  • 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. Operators ● JS : == / Coffee : is ● JS : != / Coffee : isnt ● JS : if (!false) / Coffee : if not false ● JS : && / Coffee : AND ● JS : || / Coffee : OR
  • 13. Condition statements ● if ● if not ● unless ● switch and when
  • 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. Loops ● for ● while ● until ● loop used with break !!!
  • 16. Scope ● coffee -c --bare file.coffee ● this ● root = (export ? window)
  • 17. Prototype
  • 18. Classes
  • 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. Using CoffeeScript in the Browser ● coffee -c --watch *.coffee ● coffee -c --watch o js src/*.coffee ● http://coffeescript.org/#scripts
  • 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