Your SlideShare is downloading. ×
0
*
SK Manvendra
* Getting and running it
* Variables
* “Interpolation” and “““Heredocs”””
* Statements
* Functions and Splats…
* Collectio...
* CoffeeScript is just compiled down JavaScript.
* We can write JS the way it should be…
* CS is just Syntactical Sugar fo...
* CS depends on Node.js environment to get

installed. However CS doesn’t need Node.js to
run on the machine.

* How can I...
* On command prompt type coffee. It will drop
you in REPL mode.

* Compile a file.
* Compile a folder.
* Putting output in...
* You can get compile your Coffee files to
JavaScript whenever you change them,
automatically!

coffee –cw src/ -o lib/

*...
* White space considerations.
* Indent your code properly.
* No need to use special cartoon
like characters in the code.

...
* Use of the var keyword is strictly prohibited.
* CoffeeScript saves us from creating global
variables.

* What if I need...
* “Hope if it prints the value of #{interest}.”
* A multiline string which may have
#{} can contain any
interpolation insi...
* # I’ll not be visible in compiled JavaScript.
* ###
I think I may put the license and the
information here, and it’ll be...
Equal or Identical (equal
and of the same type)?

* == or ===
* != or !==
*?

Not equal or Not
identical?
Existential oper...
CoffeeScript
* is
* isnt
* not
* and
* or
* true, yes, no
* false, no, off
* @, this
* ::
* of
* in

JavaScript
===
!==
!
...
alert “true” if var

* if var then alert “true”
* if var then alert “true” else alert “false”

That’s ternary ?:

* unless...
* switch var
when “val1”, “val2”

We don’t need the break
keyword anymore

when “val3”
else

*
I’ll be parsed to
(function() {});

* ->
Instant function
Though I’m Anonymous
* do ->
calling
* funcName = (param1, param...
* Variable number of arguments to the function.
* someFunc = (etc…) ->
Believe me it’s one
of the best aroma
of CoffeeScri...
* Arrays in CoffeeScript are no different than in
JavaScript.

* Searching.
* Swapping.
[x, y] = [y, x]
* Ranges.
* Slicin...
* Creating objects with literal syntax.
* Creating objects from variables.
* Getting and setting attributes.

*

JSON is b...
* for val in array
* for key, val of object
own may
come here

Remember the
hasOwnProperty
method?

* while condition
It’s...
* What these are?

Comprehensions are,
essentially, loops and their
code blocks on the same
line.

*
You’ll start to love
CoffeeScript

* class Employee
* The constructor function
* Inheritance

You know how the
constructor...
* <script type=“text/coffeescript”>
// Some CoffeeScript here
</script>

Before it include a reference to the url
http://j...
* How can I write jQuery using CoffeeScript?

Please see the
example app

*
* As a JavaScript replacement.
* Writing jQuery in your projects.
* Writing of JavaScript library easily.
* Writing of jQu...
*
* Now it’s your turn to make some for yourself.

*
* O’Reilly The Little Book on CoffeeScript By Alex
MacCaw

* PacktPub CoffeeScript Programming with
jQuery, Rails and Node...
Upcoming SlideShare
Loading in...5
×

CoffeeScript - An Introduction

323

Published on

An interesting presentation for learning the language from very basic. It provides very good insight to the language. JavaScript is the only prerequisite. It comes with a lot of examples that helps to learn the basics very quickly. Here is the SkyDrive download link http://sdrv.ms/16T7whf

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

  • Be the first to like this

No Downloads
Views
Total Views
323
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • name = “MSK”console.log name isnt “RK”console.log name is not “RK”
  • Transcript of "CoffeeScript - An Introduction"

    1. 1. * SK Manvendra
    2. 2. * Getting and running it * Variables * “Interpolation” and “““Heredocs””” * Statements * Functions and Splats… * Collections, Iterations and Comprehensions * Classes * Example app *
    3. 3. * CoffeeScript is just compiled down JavaScript. * We can write JS the way it should be… * CS is just Syntactical Sugar for JS. JS = -> JavaScript CS = -> CoffeeScript However, CS is more than Syntactical Sugar * If you love JS, you’ll love CS… * Let’s get to know this… * This is becoming BUZZ WORD these days…
    4. 4. * CS depends on Node.js environment to get installed. However CS doesn’t need Node.js to run on the machine. * How can I install the Node.js? * After node is installed, use NPM Perhaps, SUROOR’s blog may rescue you here… to install the CS. * npm install –g coffee-script Pay attention to “-g” * Node Package Manager
    5. 5. * On command prompt type coffee. It will drop you in REPL mode. * Compile a file. * Compile a folder. * Putting output in Read Eval Print Loop coffee –c file.coffee different folder. coffee –c src/ coffee –c src/ -o lib/ *
    6. 6. * You can get compile your Coffee files to JavaScript whenever you change them, automatically! coffee –cw src/ -o lib/ * The –w switch makes it happen. -w switch also watches for subdirectories *
    7. 7. * White space considerations. * Indent your code properly. * No need to use special cartoon like characters in the code. * Freedom from that semicolon. You’ll need me when writing multiple lines of code in a single shot * CS is very sensitive towards it Why would I need to do so? Those are really obstructive Though I’m optional in JS
    8. 8. * Use of the var keyword is strictly prohibited. * CoffeeScript saves us from creating global variables. * What if I need to create one/more? Then how would I create one? We can attach them to the global window object. But be cautious!!!
    9. 9. * “Hope if it prints the value of #{interest}.” * A multiline string which may have #{} can contain any interpolation inside it. * var regEx = /d{3}-d{8}/ This RegEx could be worse. * valid CoffeeScript inside the string Use ””” quotes that’ll even preserve the space regEx = /// d{3}d{8} ///
    10. 10. * # I’ll not be visible in compiled JavaScript. * ### I think I may put the license and the information here, and it’ll be visible in the compiled JavaScript. ### *
    11. 11. Equal or Identical (equal and of the same type)? * == or === * != or !== *? Not equal or Not identical? Existential operator 3 Usage • Variable declarations check • Object existence • Is member a method ? ?. ?() *
    12. 12. CoffeeScript * is * isnt * not * and * or * true, yes, no * false, no, off * @, this * :: * of * in JavaScript === !== ! && || true false this prototype in N/A Word of caution!!! isnt and is not are not same *
    13. 13. alert “true” if var * if var then alert “true” * if var then alert “true” else alert “false” That’s ternary ?: * unless var then alert “false” else alert “true” If the condition is false *
    14. 14. * switch var when “val1”, “val2” We don’t need the break keyword anymore when “val3” else *
    15. 15. I’ll be parsed to (function() {}); * -> Instant function Though I’m Anonymous * do -> calling * funcName = (param1, param2) -> alert “Hi” Functions can take default * someFunc = (param = val) -> arguments However if you need, you can return explicitly always If you really don’t want to return anything at the end of ->, use return null or return undefined * I’ll always return the last statement. * Hope if I could call the -> without params
    16. 16. * Variable number of arguments to the function. * someFunc = (etc…) -> Believe me it’s one of the best aroma of CoffeeScript *
    17. 17. * Arrays in CoffeeScript are no different than in JavaScript. * Searching. * Swapping. [x, y] = [y, x] * Ranges. * Slicing arrays. * Splicing/Replacing array values. Maximum size is 21 *
    18. 18. * Creating objects with literal syntax. * Creating objects from variables. * Getting and setting attributes. * JSON is breeze here
    19. 19. * for val in array * for key, val of object own may come here Remember the hasOwnProperty method? * while condition It’s our old and only friend here * You may append by and when You may append when until is not bad option either.
    20. 20. * What these are? Comprehensions are, essentially, loops and their code blocks on the same line. *
    21. 21. You’ll start to love CoffeeScript * class Employee * The constructor function * Inheritance You know how the constructor works Mmm… not exactly But it’s But there’s some hack here * Class level functions * Prototype Don’t dare to forget me Also known as noninstance functions *
    22. 22. * <script type=“text/coffeescript”> // Some CoffeeScript here </script> Before it include a reference to the url http://jashkenas.github.com/coffeescript/extras/coffee-script.js *
    23. 23. * How can I write jQuery using CoffeeScript? Please see the example app *
    24. 24. * As a JavaScript replacement. * Writing jQuery in your projects. * Writing of JavaScript library easily. * Writing of jQuery plugins easily too. * At last: The things you expect from JavaScript you can do in CoffeeScript very easily. *
    25. 25. *
    26. 26. * Now it’s your turn to make some for yourself. *
    27. 27. * O’Reilly The Little Book on CoffeeScript By Alex MacCaw * PacktPub CoffeeScript Programming with jQuery, Rails and Node.js By Michael Erasmus * The Pragmatic Programmers CoffeeScript Accelerated JavaScript Development By Trevor Burnham * O’Reilly Programming in CoffeeScript By Mark Bates *
    1. A particular slide catching your eye?

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

    ×