50 %
50 %
Information about CoffeeScript

Published on March 13, 2014

Author: AkshayMathur7



This is just a quick introduction of CoffeeScript for people to get started

Getting Started with Akshay Mathur

CoffeeScript • A language with simple syntax – No semicolons and braces – Resembles to English – Indentation decides the code blocks • Compiles into Javascript – Provides syntactic sugar for boilerplate code • Manage variable scope • Class instead of prototype – Generates good quality, error free code @akshaymathu 2

Insallation • Install Node JS and Package Manager (npm) – See for details • Install CoffeeScript – See for details sudo npm install -g coffee- script

Coffee to JS • Compile a .coffee file into .js file using coffee compiler coffee -c Creates myfile.js – See for more options and examples

Cofeescript to Javascript greet_me = (name) -> greeting_word = 'Hello!' alert "#{greeting_word} #{name}” Compiles to greet_me = function(name) { var greeting_word; greeting_word = 'Hello!'; return alert("" + greeting_word + " " + name); }; @akshaymathu 5

Variable Scoping • Defines all variables in the first line of the function – This all variables become private by default • Adds an anonymous wrapper function at the top – Even global remains within the closure – If you want to make something available outside, attach it to an object outside (e.g. window object) @akshaymathu 6

Functions • No ‘function’ keyword – Use -> instead • No curly braces {} – Indent the code instead • Last statement always returns • No parenthesis while calling the function if argument is being passed • Default values can be used in function signature @akshaymathu 7

Function Examples Fn = -> Add = (x, y=0) -> x + y Add 3 var Fn, Add; Fn = function(){}; Add = function(x, y) { if ( y == null){ y = 0; } return x + y; }; Add(3); @akshaymathu 8

Conditional Statements mood = Improved if singing if happy and knowsIt clapsHands() chaChaCha() else showIt() date = if friday then sue else jill var date, mood; if (singing) { mood = Improved; } if (happy && knowsIt) { clapsHands(); chaChaCha(); } else { showIt(); } date = friday ? sue : jill; @akshaymathu 9

Looping on Arrays using ‘in’ foods = [ 'broccoli’ 'spinach’ 'chocolate’ ] eat food for food in foods when food isnt 'chocolate' foods = ['broccoli', 'spinach', 'chocolate']; for (_k = 0, _len2 = foods.length; _k < _len2; _k++) { food = foods[_k]; if (food !== 'chocolate') { eat(food); } } @akshaymathu 10

Looping on Objects using ‘of’ yearsOld = max: 10 ida: 9 tim: 11 ages = for child, age of yearsOld "#{child} is #{age}" var age, ages, child, yearsOld; yearsOld = { max: 10, ida: 9, tim: 11 }; ages = (function() { var _results; _results = []; for (child in yearsOld) { age = yearsOld[child]; _results.push( "" + child + " is " + age ); } return _results; })(); @akshaymathu 11

Operators is === isnt !== not ! and && or || true, yes, on true false, no, off false @, this this of in in No JS equivalent @akshaymathu 12

Thanks @akshaymathu 13

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages


Note how because we are assigning the value of the comprehensions to a variable in the example above, CoffeeScript is collecting the result of each ...
Read more

CoffeeScript – Wikipedia

Der Text ist unter der Lizenz „Creative Commons Attribution/Share Alike“ verfügbar; Informationen zu den Urhebern und zum Lizenzstatus eingebundener ...
Read more

CoffeeScript - Wikipedia, the free encyclopedia

CoffeeScript is a programming language that transcompiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python and Haskell in an effort to ...
Read more

jashkenas/coffeescript · GitHub

For documentation, usage, and examples, see: To suggest a feature or report a bug:
Read more

CoffeeScript Buch von Andreas Schubert portofrei bei ...

Bücher bei Weltbild: Jetzt CoffeeScript von Andreas Schubert versandkostenfrei online kaufen & per Rechnung bezahlen bei Weltbild, Ihrem Bücher-Spezialisten!
Read more

CoffeeScript:JavaScript mit Durchblick - Host Europe ...

CoffeeScript: JavaScript mit Durchblick 15. Januar 2015 Thomas von Mengden 2 Kommentare. Obwohl JavaScript eine der am weitesten verbreiteten ...
Read more

AngularJS.DE → AngularJS + CoffeeScript - der einfachste ...

AngularJS kann nicht eleganter werden? Kein Problem, denken viele. Schon falsch. CoffeeScript 1 schafft’s. Rails 2 als technischer Vorreiter für viele ...
Read more

CoffeeScript Buch im heise shop kaufen

CoffeeScript von Andreas Schubert erschienen bei dpunkt.verlag für 22,90 € im heise shop.
Read more

Writing Better JavaScript with CoffeeScript: The Basics

This is an introductory level guide/tutorial on how to get started with CoffeeScript, a programming language that compiles to JavaScript.
Read more

CoffeeScript Tutorial - Code School - Learn to Code by ...

Gregg Pollack. Gregg is passionate about taking complex topics and teaching them efficiently. He's helped build Envy Labs, Starter Studio, and Code School.
Read more