webapplog.com @azat_co
CoffeeScript: The Good Parts
The good and not so good parts of CoffeeScript in comparison to JavaScript
1
CoffeeScript: The Good Parts The good and not so good parts of Co ff - - PowerPoint PPT Presentation
webapplog.com CoffeeScript: The Good Parts The good and not so good parts of Co ff eeScript in comparison to JavaScript @azat_co 1 webapplog.com About The Presenter Azat Mardan Worked in the US government, startups and corporations
webapplog.com @azat_co
The good and not so good parts of CoffeeScript in comparison to JavaScript
1
webapplog.com @azat_co
2
webapplog.com @azat_co
3
webapplog.com @azat_co
4
webapplog.com @azat_co
5
webapplog.com @azat_co
6
webapplog.com @azat_co
7
webapplog.com @azat_co
8
webapplog.com @azat_co
9
webapplog.com @azat_co
Maybe CoffeeScript is not so small anymore?
10
webapplog.com @azat_co
11
webapplog.com @azat_co
12
webapplog.com @azat_co
13
webapplog.com @azat_co
14
webapplog.com @azat_co
15
webapplog.com @azat_co
16
webapplog.com @azat_co
17
webapplog.com @azat_co
18
webapplog.com @azat_co
a = (x,y) -> console.log x+y var a;
return console.log(x + y); };
19
webapplog.com @azat_co
console.log @ $('div').click ()-> console.log @ console.log(this); $('div').click(function() { return console.log(this); });
20
webapplog.com @azat_co
console.log @ $('div').click ()=> console.log @ var _this = this;
return console.log(_this); });
21
webapplog.com @azat_co
22
webapplog.com @azat_co
var a = function (c) { b = 10; return b + c; } console.log(a(0));
var a = function(c) { var b = 10; return b + c; }; console.log(a(0));
23
webapplog.com @azat_co
b = 1 a = -> b = -1
console.log b var a, b; b = 1; a = function() { return b = -1; }; a(); console.log(b);
24
webapplog.com @azat_co
a = -> b = -1 b = 1 a() console.log b var a, b; a = function() { var b; return b = -1; }; b = 1; a(); console.log(b);
25
webapplog.com @azat_co
Awesome time savers! Good for arrays and objects:
webapplog.com @azat_co
for item, index in arrayObject iterator(item) var index, item, _i, _len;
_len = arrayObject.length; _i < _len; index = ++_i) { item = arrayObject[index]; iterator(item); }
27
webapplog.com @azat_co
for key, value of object iterator(value) var key, value;
value = object[key]; iterator(value); }
28
webapplog.com @azat_co
Many options:
webapplog.com @azat_co
30
webapplog.com @azat_co
class Vehicle constructor: (@name) -> move: (meters) -> console.log @name + " moved #{meters} miles.”
camry.move(50)
31
webapplog.com @azat_co
var Vehicle, camry;
function Vehicle(name) { this.name = name; }
return console.log(this.name + (" moved " + meters + " miles.")); };
32
webapplog.com @azat_co
33
webapplog.com @azat_co
34
webapplog.com @azat_co
35
webapplog.com @azat_co
webapplog.com @azat_co
37
webapplog.com @azat_co
38
webapplog.com @azat_co
39
webapplog.com @azat_co
40
webapplog.com @azat_co
41
webapplog.com @azat_co
42
webapplog.com @azat_co
43
webapplog.com @azat_co
44