Should I Use CoffeeScript? The Pros and Cons of Working With JavaScript’s Original Transpiler
-
Upload
morris-singer -
Category
Software
-
view
187 -
download
2
Transcript of Should I Use CoffeeScript? The Pros and Cons of Working With JavaScript’s Original Transpiler
WHO AM I• Lead Front End Developer
Antallagon, Inc.
• Angular.js and Node.js (Two Years)• Sencha Touch (Two Years)• Ruby on Rails (Four Years)
AGENDA
• Whirlwind tour of CoffeeScript
• A rubric for evaluating a JavaScript transpiler
• How does CoffeeScript stack up?
ARGUMENTS
function () { _.each(arguments, function (arg) { console.log(arg); } }
(args...) -> _.each args,(arg) -> console.log arg
function (a, b, c) { a = a || 1; b = b || 2; c = c || 3; }
(a = 1, b = 2, c = 3) ->
PUNCTUATIONvar obj1 = { foo: 'foo', bar: 'bar' };
obj1 = foo: 'foo' bar: 'bar'
var arr1 = [ 1, 2, 3 ];
arr1 = [ 1 2 3 ]
FLOW CONTROL (IF-ELSE)
if (foo === 'bar') console.log('hi');
console.log 'hi' if foo == 'bar'
if (foo === ‘bar') { console.log('hello'); console.log('world'); }
if foo == 'bar' console.log 'hello' console.log 'world'
var greeting = (foo === ‘bar') ? 'hello' : 'goodbye';
greeting = if foo == ‘bar' then 'hello' else 'goodbye'
FLOW CONTROL (IF NOT)
if (foo !== 'bar') console.log('hi');
console.log 'hi' unless foo == 'bar'
if (foo !== 'bar') { console.log('hello'); console.log('world'); }
unless foo == 'bar' console.log 'hello' console.log 'world'
var greeting = (foo !== 'bar') ? 'hello' : 'goodbye';
greeting = unless foo == ‘bar' then 'hello' else 'goodbye'
RANGING
var range = values.slice(1, 4); range = values[1..3]
var substr = "foobar".slice(1, 4); substr = "foobar"[1..3]
PROTOTYPING
var User = function() {}; User.prototype.approved = true;
class User User::approved = true
User.prototype.lock = function () { this.approved = false; }
User::lock = -> @approved = false
john = new User() john.picture?.thumbnail = "http://www.placehold.it/100x100"
john = new User(); if (typeof john.picture) !== undefined) { john.picture.thumbnail = 'http://www.placehold.it/100x100'; }
WHAT YOU GET
• Quirks of JavaScript are fixed
• Some nice (maybe) syntactic abstraction
• Less punctuation
• Performance (sometimes)
WHAT’S MISSING
• Strong types
• Some very important new language features
• Enhanced support for modules
• Convention