SlideShare a Scribd company logo
COFFEESCRIPT
aka AwesomeSauce
@markbates
Friday, June 7, 13
Distributed
Programmin
g with
Ruby
Addison-Wesley
2009
http://
books.markbates.com
Friday, June 7, 13
Programmi
ng
in
CoffeeScrip
Addison-Wesley
2012
http://
books.markbates.com
Friday, June 7, 13
Friday, June 7, 13
FLUENT13
first month free
www.metacasts.tv
Friday, June 7, 13
A (BRIEF) HISTORY
LESSON
Friday, June 7, 13
Friday, June 7, 13
“I need to come up with a scripting language
for web browsers.
I know! I'll make it cool and Lispy!”
Dramatic Re-enactment (1995)
Friday, June 7, 13
Friday, June 7, 13
“Yeah, So... Java is getting really popular.
So we're going to need you to rewrite your
language into something a bit more Java-
esque and name it something like JavaScript.
 
Yeah, and we're going to need it in a week.
Thanks, that'd be great.”
Dramatic Re-enactment (1995)
Friday, June 7, 13
function	
  LCMCalculator(x,	
  y)	
  {
	
  	
  var	
  checkInt	
  =	
  function(x)	
  {
	
  	
  	
  	
  if	
  (x	
  %	
  1	
  !==	
  0)	
  {
	
  	
  	
  	
  	
  	
  throw	
  new	
  TypeError(x	
  +	
  "	
  is	
  not	
  an	
  integer");
	
  	
  	
  	
  }
	
  	
  	
  	
  return	
  x;
	
  	
  };
	
  	
  this.a	
  =	
  checkInt(x)
	
  	
  this.b	
  =	
  checkInt(y);
}
LCMCalculator.prototype	
  =	
  {
	
  	
  constructor:	
  LCMCalculator,
	
  	
  gcd:	
  function()	
  {
	
  	
  	
  	
  var	
  a	
  =	
  Math.abs(this.a),
	
  	
  	
  	
  	
  	
  b	
  =	
  Math.abs(this.b),
	
  	
  	
  	
  	
  	
  t;
	
  	
  	
  	
  if	
  (a	
  <	
  b)	
  {
	
  	
  	
  	
  	
  	
  t	
  =	
  b;
	
  	
  	
  	
  	
  	
  b	
  =	
  a;
	
  	
  	
  	
  	
  	
  a	
  =	
  t;
	
  	
  	
  	
  }
	
  	
  	
  	
  while	
  (b	
  !==	
  0)	
  {
	
  	
  	
  	
  	
  	
  t	
  =	
  b;
	
  	
  	
  	
  	
  	
  b	
  =	
  a	
  %	
  b;
	
  	
  	
  	
  	
  	
  a	
  =	
  t;
	
  	
  	
  	
  }
	
  	
  	
  	
  this['gcd']	
  =	
  function()	
  {
	
  	
  	
  	
  	
  	
  return	
  a;
	
  	
  	
  	
  };
	
  	
  	
  	
  return	
  a;
	
  	
  },
	
  	
  "lcm":	
  function()	
  {
	
  	
  	
  	
  var	
  lcm	
  =	
  this.a	
  /	
  this.gcd()	
  *	
  this.b;
	
  	
  	
  	
  this.lcm	
  =	
  function()	
  {
	
  	
  	
  	
  	
  	
  return	
  lcm;
	
  	
  	
  	
  };
	
  	
  	
  	
  return	
  lcm;
	
  	
  },
	
  	
  toString:	
  function()	
  {
	
  	
  	
  	
  return	
  "LCMCalculator:	
  a	
  =	
  "	
  +	
  this.a	
  +	
  ",	
  b	
  =	
  "	
  +	
  this.b;
	
  	
  }
};
	
  
function	
  output(x)	
  {
	
  	
  document.body.appendChild(document.createTextNode(x));
	
  	
  document.body.appendChild(document.createElement('br'));
}
	
  
[
	
  	
  [25,	
  55],
	
  	
  [21,	
  56],
	
  	
  [22,	
  58],
	
  	
  [28,	
  56]
].map(function(pair)	
  {
	
  	
  return	
  new	
  LCMCalculator(pair[0],	
  pair[1]);
}).sort(function(a,	
  b)	
  {
	
  	
  return	
  a.lcm()	
  -­‐	
  b.lcm();
}).forEach(function(obj)	
  {
	
  	
  output(obj	
  +	
  ",	
  gcd	
  =	
  "	
  +	
  obj.gcd()	
  +	
  ",	
  lcm	
  =	
  "	
  +	
  obj.lcm());
});
Friday, June 7, 13
FAST FORWARD
About 15 Years
Friday, June 7, 13
Friday, June 7, 13
function	
  LCMCalculator(x,	
  y)	
  {
	
  	
  var	
  checkInt	
  =	
  function(x)	
  {
	
  	
  	
  	
  if	
  (x	
  %	
  1	
  !==	
  0)	
  {
	
  	
  	
  	
  	
  	
  throw	
  new	
  TypeError(x	
  +	
  "	
  is	
  not	
  an	
  integer");
	
  	
  	
  	
  }
	
  	
  	
  	
  return	
  x;
	
  	
  };
	
  	
  this.a	
  =	
  checkInt(x)
	
  	
  this.b	
  =	
  checkInt(y);
}
LCMCalculator.prototype	
  =	
  {
	
  	
  constructor:	
  LCMCalculator,
	
  	
  gcd:	
  function()	
  {
	
  	
  	
  	
  var	
  a	
  =	
  Math.abs(this.a),
	
  	
  	
  	
  	
  	
  b	
  =	
  Math.abs(this.b),
	
  	
  	
  	
  	
  	
  t;
	
  	
  	
  	
  if	
  (a	
  <	
  b)	
  {
	
  	
  	
  	
  	
  	
  t	
  =	
  b;
	
  	
  	
  	
  	
  	
  b	
  =	
  a;
	
  	
  	
  	
  	
  	
  a	
  =	
  t;
	
  	
  	
  	
  }
	
  	
  	
  	
  while	
  (b	
  !==	
  0)	
  {
	
  	
  	
  	
  	
  	
  t	
  =	
  b;
	
  	
  	
  	
  	
  	
  b	
  =	
  a	
  %	
  b;
	
  	
  	
  	
  	
  	
  a	
  =	
  t;
	
  	
  	
  	
  }
	
  	
  	
  	
  this['gcd']	
  =	
  function()	
  {
	
  	
  	
  	
  	
  	
  return	
  a;
	
  	
  	
  	
  };
	
  	
  	
  	
  return	
  a;
	
  	
  },
	
  	
  "lcm":	
  function()	
  {
	
  	
  	
  	
  var	
  lcm	
  =	
  this.a	
  /	
  this.gcd()	
  *	
  this.b;
	
  	
  	
  	
  this.lcm	
  =	
  function()	
  {
	
  	
  	
  	
  	
  	
  return	
  lcm;
	
  	
  	
  	
  };
	
  	
  	
  	
  return	
  lcm;
	
  	
  },
	
  	
  toString:	
  function()	
  {
	
  	
  	
  	
  return	
  "LCMCalculator:	
  a	
  =	
  "	
  +	
  this.a	
  +	
  ",	
  b	
  =	
  "	
  +	
  this.b;
	
  	
  }
};
	
  
function	
  output(x)	
  {
	
  	
  document.body.appendChild(document.createTextNode(x));
	
  	
  document.body.appendChild(document.createElement('br'));
}
	
  
[
	
  	
  [25,	
  55],
	
  	
  [21,	
  56],
	
  	
  [22,	
  58],
	
  	
  [28,	
  56]
].map(function(pair)	
  {
	
  	
  return	
  new	
  LCMCalculator(pair[0],	
  pair[1]);
}).sort(function(a,	
  b)	
  {
	
  	
  return	
  a.lcm()	
  -­‐	
  b.lcm();
}).forEach(function(obj)	
  {
	
  	
  output(obj	
  +	
  ",	
  gcd	
  =	
  "	
  +	
  obj.gcd()	
  +	
  ",	
  lcm	
  =	
  "	
  +	
  obj.lcm());
});
Friday, June 7, 13
class	
  LCMCalculator
	
  
	
  	
  constructor:	
  (x,	
  y)	
  -­‐>
	
  	
  	
  	
  checkInt	
  =	
  (x)	
  -­‐>
	
  	
  	
  	
  	
  	
  if	
  x	
  %	
  1	
  isnt	
  0
	
  	
  	
  	
  	
  	
  	
  	
  throw	
  new	
  TypeError(x	
  +	
  "	
  is	
  not	
  an	
  integer")
	
  	
  	
  	
  	
  	
  return	
  x
	
  
	
  	
  	
  	
  @a	
  =	
  checkInt(x)
	
  	
  	
  	
  @b	
  =	
  checkInt(y)
	
  
	
  	
  gcd:	
  -­‐>
	
  	
  	
  	
  a	
  =	
  Math.abs(@a)
	
  	
  	
  	
  b	
  =	
  Math.abs(@b)
	
  	
  	
  	
  t	
  =	
  undefined
	
  	
  	
  	
  if	
  a	
  <	
  b
	
  	
  	
  	
  	
  	
  t	
  =	
  b
	
  	
  	
  	
  	
  	
  b	
  =	
  a
	
  	
  	
  	
  	
  	
  a	
  =	
  t
	
  	
  	
  	
  while	
  b	
  isnt	
  0
	
  	
  	
  	
  	
  	
  t	
  =	
  b
	
  	
  	
  	
  	
  	
  b	
  =	
  a	
  %	
  b
	
  	
  	
  	
  	
  	
  a	
  =	
  t
	
  	
  	
  	
  this["gcd"]	
  =	
  -­‐>	
  a
	
  	
  	
  	
  return	
  a
	
  
	
  	
  lcm:	
  -­‐>
	
  	
  	
  	
  lcm	
  =	
  @a	
  /	
  @gcd()	
  *	
  @b
	
  	
  	
  	
  @lcm	
  =	
  -­‐>	
  lcm
	
  	
  	
  	
  return	
  lcm
	
  
	
  	
  toString:	
  -­‐>
	
  	
  	
  	
  "LCMCalculator:	
  a	
  =	
  #{@a},	
  b	
  =	
  #{@b}"
output	
  =	
  (x)	
  -­‐>
	
  	
  document.body.appendChild	
  document.createTextNode(x)
	
  	
  document.body.appendChild	
  document.createElement("br")
	
  
[[25,	
  55],	
  [21,	
  56],	
  [22,	
  58],	
  [28,	
  56]].map((pair)	
  -­‐>
	
  	
  new	
  LCMCalculator(pair[0],	
  pair[1])
).sort((a,	
  b)	
  -­‐>
	
  	
  a.lcm()	
  -­‐	
  b.lcm()
).forEach	
  (obj)	
  -­‐>
	
  	
  output	
  "obj	
  #{gcd}	
  =	
  #{obj.gcd()},	
  lcm	
  =	
  #{obj.lcm()}"
Friday, June 7, 13
WHAT IS COFFEESCRIPT?
Friday, June 7, 13
What is CoffeeScript?
Friday, June 7, 13
“A little language that compiles into JavaScript.”
What is CoffeeScript?
Friday, June 7, 13
“A little language that compiles into JavaScript.”
Easily integrates with your current JavaScript
What is CoffeeScript?
Friday, June 7, 13
“A little language that compiles into JavaScript.”
Easily integrates with your current JavaScript
Easier to read, write, maintain, refactor, etc...
What is CoffeeScript?
Friday, June 7, 13
“A little language that compiles into JavaScript.”
Easily integrates with your current JavaScript
Easier to read, write, maintain, refactor, etc...
A Hybrid languages like Ruby and Python.
What is CoffeeScript?
Friday, June 7, 13
“A little language that compiles into JavaScript.”
Easily integrates with your current JavaScript
Easier to read, write, maintain, refactor, etc...
A Hybrid languages like Ruby and Python.
Helpful.
What is CoffeeScript?
Friday, June 7, 13
Not Magic!
Limited by what JavaScript can already do
What CoffeeScript Is
Not?
Friday, June 7, 13
“I’m happy writing JavaScript.
I don’t need to learn another language.”
Friday, June 7, 13
FINE WITH ME
Friday, June 7, 13
BUT...
Friday, June 7, 13
ANOTHER (BRIEF)
HISTORY LESSON
Friday, June 7, 13
.MODEL SMALL
.STACK 64
.DATA
VAL1 DB 01H
VAL2 DB 01H
LP DB 00H
V1 DB 00H
V2 DB 00H
NL DB 0DH,0AH,'$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH,01H
INT 21H
MOV CL,AL
SUB CL,30H
SUB CL,2
MOV AH,02H
MOV DL,VAL1
ADD DL,30H
INT 21H
MOV AH,09H
LEA DX,NL
INT 21H
MOV AH,02H
MOV DL,VAL2
ADD DL,30H
INT 21H
MOV AH,09H
LEA DX,NL
INT 21H
DISP:
MOV BL,VAL1
ADD BL,VAL2
MOV AH,00H
MOV AL,BL
MOV LP,CL
MOV CL,10
DIV CL
MOV CL,LP
MOV V1,AL
MOV V2,AH
MOV DL,V1
ADD DL,30H
MOV AH,02H
INT 21H
MOV DL,V2
ADD DL,30H
MOV AH,02H
INT 21H
MOV DL,VAL2
MOV VAL1,DL
MOV VAL2,BL
MOV AH,09H
LEA DX,NL
INT 21H
LOOP DISP
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
Friday, June 7, 13
.MODEL SMALL
.STACK 64
.DATA
VAL1 DB 01H
VAL2 DB 01H
LP DB 00H
V1 DB 00H
V2 DB 00H
NL DB 0DH,0AH,'$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH,01H
INT 21H
MOV CL,AL
SUB CL,30H
SUB CL,2
MOV AH,02H
MOV DL,VAL1
ADD DL,30H
INT 21H
MOV AH,09H
LEA DX,NL
INT 21H
MOV AH,02H
MOV DL,VAL2
ADD DL,30H
INT 21H
MOV AH,09H
LEA DX,NL
INT 21H
DISP:
MOV BL,VAL1
ADD BL,VAL2
MOV AH,00H
MOV AL,BL
MOV LP,CL
MOV CL,10
DIV CL
MOV CL,LP
MOV V1,AL
MOV V2,AH
MOV DL,V1
ADD DL,30H
MOV AH,02H
INT 21H
MOV DL,V2
ADD DL,30H
MOV AH,02H
INT 21H
MOV DL,VAL2
MOV VAL1,DL
MOV VAL2,BL
MOV AH,09H
LEA DX,NL
INT 21H
LOOP DISP
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
Assembly
Friday, June 7, 13
#include <stdio.h>
int fibonacci()
{
int n = 100;
int a = 0;
int b = 1;
int sum;
int i;
for (i = 0; i < n; i++)
{
printf("%dn", a);
sum = a + b;
a = b;
b = sum;
}
return 0;
}
C
Friday, June 7, 13
public static void fibonacci() {
int n = 100;
int a = 0;
int b = 1;
for (int i = 0; i < n; i++) {
System.out.println(a);
a = a + b;
b = a - b;
}
}
Java
Friday, June 7, 13
def fibonacci
a = 0
b = 1
100.times do
printf("%dn", a)
a, b = b, a + b
end
end
Ruby
Friday, June 7, 13
“I can write an app just as well in Java
as I can in Ruby, but damn it if Ruby
isn’t nicer to read and write!”
Friday, June 7, 13
SAME GOES FOR
COFFEESCRIPT
Friday, June 7, 13
SYNTAX
Friday, June 7, 13
$(function() {
success = function(data) {
if (data.errors != null) {
alert("There was an error!");
} else {
$("#content").text(data.message);
}
};
$.get('/users', success, 'json');
});
$ ->
success = (data) ->
if data.errors?
alert "There was an error!"
else
$("#content").text(data.message)
$.get('/users', success, 'json')
JavaScript CoffeeScript
Friday, June 7, 13
Syntax Rules
No semi-colons (ever!)
No curly braces*
No ‘function’ keyword
Relaxed parentheses
Whitespace significant formatting
Friday, June 7, 13
# Not required without arguments:
noArg1 = ->
# do something
# Not required without arguments:
noArg2 = () ->
# do something
# Required with Arguments:
withArg = (arg) ->
# do something
Parentheses Rules
# Required without arguments:
noArg1()
noArg2()
# Not required with
arguments:
withArg("bar")
withArg "bar"
Friday, June 7, 13
# Bad:
$ "#some_id" .text()
# $("#some_id".text());
# Good:
$("#some_id").text()
# $("#some_id").text();
Parentheses Rules
Friday, June 7, 13
Whitespace
Friday, June 7, 13
Whitespace
$(function() {
success = function(data) {
if (data.errors != null) {
alert("There was an error!");
} else {
$("#content").text(data.message);
}
};
$.get('/users', success, 'json');
});
Friday, June 7, 13
Whitespace
$(function() {
success = function(data) {
if (data.errors != null) {
alert("There was an error!");
} else {
$("#content").text(data.message);
}
};
$.get('/users', success, 'json');
});
Friday, June 7, 13
Whitespace
$ ->
success = (data) ->
if data.errors?
alert "There was an error!"
else
$("#content").text(data.message)
$.get('/users', success, 'json')
Friday, June 7, 13
Conditionals
doSomething() if true
doSomething() unless true
if true
doSomething()
unless true
doSomething()
if true
doSomething()
else
doSomethingElse()
Friday, June 7, 13
Objects/Hashes
someObject = {conf: "FluentConf", talk: "CoffeeScript"}
someObject =
conf: "FluentConf"
talk: "CoffeeScript"
someFunction(conf: "FluentConf", talk: "CoffeeScript")
Friday, June 7, 13
Objects/Hashes
var someObject;
someObject = {
conf: "FluentConf",
talk: "CoffeeScript"
};
someObject = {
conf: "FluentConf",
talk: "CoffeeScript"
};
someFunction({
conf: "FluentConf",
talk: "CoffeeScript"
});
Friday, June 7, 13
String Interpolation
name = "FluentConf 2013"
console.log "Hello #{name}"
# Hello FluentConf 2013
console.log 'Hello #{name}'
# Hello #{name}
Friday, June 7, 13
String Interpolation
name = "FluentConf 2013"
console.log "Hello #{name}"
# Hello FluentConf 2013
console.log 'Hello #{name}'
# Hello #{name}
var name;
name = "FluentConf 2013";
console.log("Hello " + name);
console.log('Hello #{name}');
Friday, June 7, 13
Heredocs
html = """
<div class="comment" id="tweet-#{tweet.id_str}">
<hr>
<div class='tweet'>
<span class="imgr"><img
src="#{tweet.profile_image_url}"></span>
<span class="txtr">
<h5><a href="http://twitter.com/#{tweet.from_user}"
target="_blank">@#{tweet.from_user}</a></h5>
<p>#{tweet.text}</p>
<p class="comment-posted-on">#{tweet.created_at}</p>
</span>
</div>
</div>
"""
Friday, June 7, 13
Heredocs
var html;
html = "<div class="comment" id="tweet-" + tweet.id_str
+ "">n <hr>n <div class='tweet'>n <span class=
"imgr"><img src="" + tweet.profile_image_url + ""></
span>n <span class="txtr">n <h5><a href=
"http://twitter.com/" + tweet.from_user + "" target=
"_blank">@" + tweet.from_user + "</a></h5>n <p>" +
tweet.text + "</p>n <p class="comment-posted-on">"
+ tweet.created_at + "</p>n </span>n </div>n</div>";
Friday, June 7, 13
Functions
p = (name) ->
console.log "Hello #{name}"
p('FluentConf 2013')
Friday, June 7, 13
Functions
var p;
p = function(name) {
return console.log("Hello " + name);
};
p('FluentConf 2013');
Friday, June 7, 13
Loops &
Comprehensions
for someName in someArray
console.log someName
for key, value of someObject
console.log "#{key}: #{value}"
Friday, June 7, 13
Loops &
Comprehensions
var key, someName, value, _i, _len;
for (_i = 0, _len = someArray.length; _i < _len; _i++) {
someName = someArray[_i];
console.log(someName);
}
for (key in someObject) {
value = someObject[key];
console.log("" + key + ": " + value);
}
Friday, June 7, 13
Loops &
Comprehensions
numbers = [1..5]
console.log number for number in numbers
Friday, June 7, 13
Loops &
Comprehensions
var number, numbers, _i, _len;
numbers = [1, 2, 3, 4, 5];
for (_i = 0, _len = numbers.length; _i < _len; _i++) {
number = numbers[_i];
console.log(number);
}
Friday, June 7, 13
Loops &
Comprehensions
numbers = [1..5]
console.log number for number in numbers when number <= 3
Friday, June 7, 13
Loops &
Comprehensions
var number, numbers, _i, _len;
numbers = [1, 2, 3, 4, 5];
for (_i = 0, _len = numbers.length; _i < _len; _i++) {
number = numbers[_i];
if (number <= 3) {
console.log(number);
}
}
Friday, June 7, 13
Loops &
Comprehensions
numbers = [1, 2, 3, 4, 5]
low_numbers = (number * 2 for number in numbers when number <= 3)
console.log low_numbers # [ 2, 4, 6 ]
Friday, June 7, 13
Loops &
Comprehensions
var low_numbers, number, numbers;
numbers = [1, 2, 3, 4, 5];
low_numbers = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = numbers.length; _i < _len; _i++) {
number = numbers[_i];
if (number <= 3) {
_results.push(number * 2);
}
}
return _results;
})();
console.log(low_numbers);
Friday, June 7, 13
Classes
class Employee
emp = new Employee()
emp.firstName = "Mark"
Friday, June 7, 13
Classes
var Employee, emp;
Employee = (function() {
Employee.name = 'Employee';
function Employee() {}
return Employee;
})();
emp = new Employee();
emp.firstName = "Mark";
Friday, June 7, 13
Classes
class Employee
constructor: (@options = {}) ->
salary: ->
@options.salary ?= "$250,000"
emp = new Employee()
console.log emp.salary() # "$250,000"
emp = new Employee(salary: "$100,000")
console.log emp.salary() # "$100,000"
Friday, June 7, 13
Classes
var Employee, emp;
Employee = (function() {
Employee.name = 'Employee';
function Employee(options) {
this.options = options != null ? options : {};
}
Employee.prototype.salary = function() {
var _base, _ref;
return (_ref = (_base = this.options).salary) != null ? _ref : _base.salary = "$250,000";
};
return Employee;
})();
emp = new Employee();
console.log(emp.salary());
emp = new Employee({
salary: "$100,000"
});
console.log(emp.salary());
Friday, June 7, 13
Extending Classes
class Manager extends Employee
salary: ->
"#{super} w/ $10k Bonus"
manager = new Manager()
console.log manager.salary() # "$250,000 w/ $10k Bonus"
Friday, June 7, 13
Extending Classes
var Manager, manager,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ =
parent.prototype; return child; };
Manager = (function(_super) {
__extends(Manager, _super);
Manager.name = 'Manager';
function Manager() {
var _base;
Manager.__super__.constructor.apply(this, arguments);
}
Manager.prototype.salary = function() {
return "" + Manager.__super__.salary.apply(this, arguments) + " w/ $10k Bonus";
};
return Manager;
})(Employee);
manager = new Manager();
console.log(manager.salary());
Friday, June 7, 13
Bound Functions
class User
constructor: (@name) ->
sayHi: ->
console.log "Hello #{@name}"
bob = new User('bob')
mary = new User('mary')
log = (callback)->
console.log "about to execute callback..."
callback()
console.log "...executed callback"
log(bob.sayHi)
log(mary.sayHi)
Friday, June 7, 13
Bound Functions
about to execute callback...
Hello undefined
...executed callback
about to execute callback...
Hello undefined
...executed callback
Friday, June 7, 13
class User
constructor: (@name) ->
sayHi: ->
console.log "Hello #{@name}"
bob = new User('bob')
mary = new User('mary')
log = (callback)->
console.log "about to execute callback..."
callback()
console.log "...executed callback"
log(bob.sayHi)
log(mary.sayHi)
Bound Functions
Friday, June 7, 13
class User
constructor: (@name) ->
sayHi: ->
console.log "Hello #{@name}"
bob = new User('bob')
mary = new User('mary')
log = (callback)->
console.log "about to execute callback..."
callback()
console.log "...executed callback"
log(bob.sayHi)
log(mary.sayHi)
Bound Functions
Friday, June 7, 13
class User
constructor: (@name) ->
sayHi: =>
console.log "Hello #{@name}"
bob = new User('bob')
mary = new User('mary')
log = (callback)->
console.log "about to execute callback..."
callback()
console.log "...executed callback"
log(bob.sayHi)
log(mary.sayHi)
Bound Functions
Friday, June 7, 13
Bound Functions
about to execute callback...
Hello bob
...executed callback
about to execute callback...
Hello mary
...executed callback
Friday, June 7, 13
Bound Functions
class User
constructor: (@name) ->
sayHi: =>
console.log "Hello #{@name}"
Friday, June 7, 13
Bound Functions
var User,
__bind = function(fn, me){ return function(){ return fn.apply(me,
arguments); }; };
User = (function() {
User.name = 'User';
function User(name) {
this.name = name;
this.sayHi = __bind(this.sayHi, this);
}
User.prototype.sayHi = function() {
return console.log("Hello " + this.name);
};
return User;
})();
Friday, June 7, 13
FINALLY
One of my favorite features
Friday, June 7, 13
Existential Operator
if foo?
console.log "foo"
Friday, June 7, 13
Existential Operator
if (typeof foo !== "undefined" && foo !== null) {
console.log("foo");
}
Friday, June 7, 13
BUT WAIT! THERE’S
MORE!
Friday, June 7, 13
Existential Operator
console?.log "foo"
Friday, June 7, 13
Existential Operator
console?.log "foo"
if (typeof console !== "undefined" && console !== null) {
console.log("foo");
}
Friday, June 7, 13
Existential Operator
if currentUser?.firstName?
console.log currentUser.firstName
Friday, June 7, 13
Existential Operator
if currentUser?.firstName?
console.log currentUser.firstName
if ((typeof currentUser !== "undefined" && currentUser !==
null ? currentUser.firstName : void 0) != null) {
console.log(currentUser.firstName);
}
Friday, June 7, 13
FINALLY
Friday, June 7, 13
The Raven
Friday, June 7, 13
Once upon a mignight dreary while I pondered, weak and weary,
Over many quaint and curious volume of forgotten lore -
While I nodded, nearly napping, suddenly there came a tapping,
As of some one gently rapping, rapping at my chamber door
"'Tis some visiter". I muttered, "tapping at my chamber door" -
"only this and nothing more."
Ah distinctly I remember it was in the bleak December;
And each separate dying ember wrought its ghost upon the floor.
Eagerly I wished the morrow - vainly I had sought to borrow,
From my books surcease of sorrow - sorrow For the lost Lenore -
For the rare and radiant maiden whom the angels name Lenore -
Nameless here For evermore
The Raven
Friday, June 7, 13
The Raven
var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length;
i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
while (I(pondered, weak && weary, Over(many(quaint && curious(volume in
forgotten(lore - While(I(nodded, nearly(napping, suddenly(there(came(a(tapping,
As in some(one(gently(rapping, rapping(at(my(chamber(door)))))))))))))))))))) {
  Once(upon(a(mignight(dreary))));
}
"'Tis some visiter".I(muttered, "tapping at my chamber door" - "only this and
nothing more.");
Ah(distinctly(I(remember(it(__indexOf.call(the(bleak(December)), was) >= 0)))));
And(each(separate(dying(ember(wrought(its(ghost(upon(the(floor.Eagerly(I(wished(
the(morrow - vainly(I(had(sought(to(borrow, From(my(books(surcease in sorrow -
sorrow(For(the(lost(Lenore - For(the(rare &&
radiant(maiden(whom(the(angels(name(Lenore -
Nameless(here(For(evermore)))))))))))))))))))))))))))))))))))));
Friday, June 7, 13
What Didn’t I Cover?
Default Arguments
Ranges
Splatted Arguments
Scoping
Security
Strict Mode
Fixes common
‘mistakes’
Operators
The `do` keyword
Source Maps
Plenty more!
Friday, June 7, 13
Thank you!
Friday, June 7, 13
Thank you!
myName = "Mark Bates"
you.should buyBook("Programming in CoffeeScript")
.at("http://books.markbates.com")
you.should follow(@markbates)
Friday, June 7, 13

More Related Content

What's hot

서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
NAVER / MusicPlatform
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
名辰 洪
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# Developers
Rick Beerendonk
 
Rxjs kyivjs 2015
Rxjs kyivjs 2015Rxjs kyivjs 2015
Rxjs kyivjs 2015
Alexander Mostovenko
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
Caridy Patino
 
Functional Reactive Programming with RxJS
Functional Reactive Programming with RxJSFunctional Reactive Programming with RxJS
Functional Reactive Programming with RxJS
stefanmayer13
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simplerAlexander Mostovenko
 
Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012
aleks-f
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
Alex Payne
 
Oop assignment 02
Oop assignment 02Oop assignment 02
Oop assignment 02
MamoonKhan39
 
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Igalia
 
RxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrowRxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrow
Viliam Elischer
 
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)
Shift Conference
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
aleks-f
 
Functional programming with Immutable .JS
Functional programming with Immutable .JSFunctional programming with Immutable .JS
Functional programming with Immutable .JS
Laura Steggles
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular
500Tech
 
如何「畫圖」寫測試 - RxJS Marble Test
如何「畫圖」寫測試 - RxJS Marble Test如何「畫圖」寫測試 - RxJS Marble Test
如何「畫圖」寫測試 - RxJS Marble Test
名辰 洪
 
SOLID principles in practice: the Clean Architecture
SOLID principles in practice: the Clean ArchitectureSOLID principles in practice: the Clean Architecture
SOLID principles in practice: the Clean Architecture
Fabio Collini
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
Binary Studio
 

What's hot (20)

서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# Developers
 
Rxjs kyivjs 2015
Rxjs kyivjs 2015Rxjs kyivjs 2015
Rxjs kyivjs 2015
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
 
Functional Reactive Programming with RxJS
Functional Reactive Programming with RxJSFunctional Reactive Programming with RxJS
Functional Reactive Programming with RxJS
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simpler
 
Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
 
Oop assignment 02
Oop assignment 02Oop assignment 02
Oop assignment 02
 
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
 
RxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrowRxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrow
 
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
 
Functional programming with Immutable .JS
Functional programming with Immutable .JSFunctional programming with Immutable .JS
Functional programming with Immutable .JS
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular
 
如何「畫圖」寫測試 - RxJS Marble Test
如何「畫圖」寫測試 - RxJS Marble Test如何「畫圖」寫測試 - RxJS Marble Test
如何「畫圖」寫測試 - RxJS Marble Test
 
Yavorsky
YavorskyYavorsky
Yavorsky
 
SOLID principles in practice: the Clean Architecture
SOLID principles in practice: the Clean ArchitectureSOLID principles in practice: the Clean Architecture
SOLID principles in practice: the Clean Architecture
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 

Similar to CoffeeScript

Groovy
GroovyGroovy
Groovy
Zen Urban
 
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis GraphRedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
Redis Labs
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
HODZoology3
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
Vikas Sharma
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
James Ford
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
David Furber
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs偉格 高
 
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
Matt Moores
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
Skills Matter
 
Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....
Raffi Krikorian
 
Vb scripting
Vb scriptingVb scripting
Vb scripting
Rajanikanth Bandela
 
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdfreservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
RTEFGDFGJU
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2goMoriyoshi Koizumi
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
JAXLondon_Conference
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScript
ChengHui Weng
 
Operators
OperatorsOperators
Operators
Daman Toor
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
Manoj Kumar
 

Similar to CoffeeScript (20)

Groovy
GroovyGroovy
Groovy
 
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis GraphRedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....
 
Vb scripting
Vb scriptingVb scripting
Vb scripting
 
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdfreservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScript
 
Scala en
Scala enScala en
Scala en
 
Matlab1
Matlab1Matlab1
Matlab1
 
Operators
OperatorsOperators
Operators
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 

More from Mark

Building Go Web Apps
Building Go Web AppsBuilding Go Web Apps
Building Go Web Apps
Mark
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
Mark
 
Go(lang) for the Rubyist
Go(lang) for the RubyistGo(lang) for the Rubyist
Go(lang) for the Rubyist
Mark
 
Mangling Ruby with TracePoint
Mangling Ruby with TracePointMangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mark
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
Mark
 
A Big Look at MiniTest
A Big Look at MiniTestA Big Look at MiniTest
A Big Look at MiniTest
Mark
 
A Big Look at MiniTest
A Big Look at MiniTestA Big Look at MiniTest
A Big Look at MiniTest
Mark
 
GET /better
GET /betterGET /better
GET /better
Mark
 
Testing Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScriptTesting Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScript
Mark
 
Building an API in Rails without Realizing It
Building an API in Rails without Realizing ItBuilding an API in Rails without Realizing It
Building an API in Rails without Realizing It
Mark
 
5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(
Mark
 
CoffeeScript for the Rubyist
CoffeeScript for the RubyistCoffeeScript for the Rubyist
CoffeeScript for the Rubyist
Mark
 
RubyMotion
RubyMotionRubyMotion
RubyMotion
Mark
 
Testing JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and ChaiTesting JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and Chai
Mark
 
CoffeeScript for the Rubyist
CoffeeScript for the RubyistCoffeeScript for the Rubyist
CoffeeScript for the Rubyist
Mark
 
Testing Rich Client Side Apps with Jasmine
Testing Rich Client Side Apps with JasmineTesting Rich Client Side Apps with Jasmine
Testing Rich Client Side Apps with Jasmine
Mark
 
DRb and Rinda
DRb and RindaDRb and Rinda
DRb and Rinda
Mark
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
Mark
 
Distributed Programming with Ruby/Rubyconf 2010
Distributed Programming with Ruby/Rubyconf 2010Distributed Programming with Ruby/Rubyconf 2010
Distributed Programming with Ruby/Rubyconf 2010
Mark
 

More from Mark (19)

Building Go Web Apps
Building Go Web AppsBuilding Go Web Apps
Building Go Web Apps
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
 
Go(lang) for the Rubyist
Go(lang) for the RubyistGo(lang) for the Rubyist
Go(lang) for the Rubyist
 
Mangling Ruby with TracePoint
Mangling Ruby with TracePointMangling Ruby with TracePoint
Mangling Ruby with TracePoint
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
 
A Big Look at MiniTest
A Big Look at MiniTestA Big Look at MiniTest
A Big Look at MiniTest
 
A Big Look at MiniTest
A Big Look at MiniTestA Big Look at MiniTest
A Big Look at MiniTest
 
GET /better
GET /betterGET /better
GET /better
 
Testing Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScriptTesting Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScript
 
Building an API in Rails without Realizing It
Building an API in Rails without Realizing ItBuilding an API in Rails without Realizing It
Building an API in Rails without Realizing It
 
5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(
 
CoffeeScript for the Rubyist
CoffeeScript for the RubyistCoffeeScript for the Rubyist
CoffeeScript for the Rubyist
 
RubyMotion
RubyMotionRubyMotion
RubyMotion
 
Testing JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and ChaiTesting JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and Chai
 
CoffeeScript for the Rubyist
CoffeeScript for the RubyistCoffeeScript for the Rubyist
CoffeeScript for the Rubyist
 
Testing Rich Client Side Apps with Jasmine
Testing Rich Client Side Apps with JasmineTesting Rich Client Side Apps with Jasmine
Testing Rich Client Side Apps with Jasmine
 
DRb and Rinda
DRb and RindaDRb and Rinda
DRb and Rinda
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
Distributed Programming with Ruby/Rubyconf 2010
Distributed Programming with Ruby/Rubyconf 2010Distributed Programming with Ruby/Rubyconf 2010
Distributed Programming with Ruby/Rubyconf 2010
 

Recently uploaded

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 

Recently uploaded (20)

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 

CoffeeScript

  • 8. “I need to come up with a scripting language for web browsers. I know! I'll make it cool and Lispy!” Dramatic Re-enactment (1995) Friday, June 7, 13
  • 10. “Yeah, So... Java is getting really popular. So we're going to need you to rewrite your language into something a bit more Java- esque and name it something like JavaScript.   Yeah, and we're going to need it in a week. Thanks, that'd be great.” Dramatic Re-enactment (1995) Friday, June 7, 13
  • 11. function  LCMCalculator(x,  y)  {    var  checkInt  =  function(x)  {        if  (x  %  1  !==  0)  {            throw  new  TypeError(x  +  "  is  not  an  integer");        }        return  x;    };    this.a  =  checkInt(x)    this.b  =  checkInt(y); } LCMCalculator.prototype  =  {    constructor:  LCMCalculator,    gcd:  function()  {        var  a  =  Math.abs(this.a),            b  =  Math.abs(this.b),            t;        if  (a  <  b)  {            t  =  b;            b  =  a;            a  =  t;        }        while  (b  !==  0)  {            t  =  b;            b  =  a  %  b;            a  =  t;        }        this['gcd']  =  function()  {            return  a;        };        return  a;    },    "lcm":  function()  {        var  lcm  =  this.a  /  this.gcd()  *  this.b;        this.lcm  =  function()  {            return  lcm;        };        return  lcm;    },    toString:  function()  {        return  "LCMCalculator:  a  =  "  +  this.a  +  ",  b  =  "  +  this.b;    } };   function  output(x)  {    document.body.appendChild(document.createTextNode(x));    document.body.appendChild(document.createElement('br')); }   [    [25,  55],    [21,  56],    [22,  58],    [28,  56] ].map(function(pair)  {    return  new  LCMCalculator(pair[0],  pair[1]); }).sort(function(a,  b)  {    return  a.lcm()  -­‐  b.lcm(); }).forEach(function(obj)  {    output(obj  +  ",  gcd  =  "  +  obj.gcd()  +  ",  lcm  =  "  +  obj.lcm()); }); Friday, June 7, 13
  • 12. FAST FORWARD About 15 Years Friday, June 7, 13
  • 14. function  LCMCalculator(x,  y)  {    var  checkInt  =  function(x)  {        if  (x  %  1  !==  0)  {            throw  new  TypeError(x  +  "  is  not  an  integer");        }        return  x;    };    this.a  =  checkInt(x)    this.b  =  checkInt(y); } LCMCalculator.prototype  =  {    constructor:  LCMCalculator,    gcd:  function()  {        var  a  =  Math.abs(this.a),            b  =  Math.abs(this.b),            t;        if  (a  <  b)  {            t  =  b;            b  =  a;            a  =  t;        }        while  (b  !==  0)  {            t  =  b;            b  =  a  %  b;            a  =  t;        }        this['gcd']  =  function()  {            return  a;        };        return  a;    },    "lcm":  function()  {        var  lcm  =  this.a  /  this.gcd()  *  this.b;        this.lcm  =  function()  {            return  lcm;        };        return  lcm;    },    toString:  function()  {        return  "LCMCalculator:  a  =  "  +  this.a  +  ",  b  =  "  +  this.b;    } };   function  output(x)  {    document.body.appendChild(document.createTextNode(x));    document.body.appendChild(document.createElement('br')); }   [    [25,  55],    [21,  56],    [22,  58],    [28,  56] ].map(function(pair)  {    return  new  LCMCalculator(pair[0],  pair[1]); }).sort(function(a,  b)  {    return  a.lcm()  -­‐  b.lcm(); }).forEach(function(obj)  {    output(obj  +  ",  gcd  =  "  +  obj.gcd()  +  ",  lcm  =  "  +  obj.lcm()); }); Friday, June 7, 13
  • 15. class  LCMCalculator      constructor:  (x,  y)  -­‐>        checkInt  =  (x)  -­‐>            if  x  %  1  isnt  0                throw  new  TypeError(x  +  "  is  not  an  integer")            return  x          @a  =  checkInt(x)        @b  =  checkInt(y)      gcd:  -­‐>        a  =  Math.abs(@a)        b  =  Math.abs(@b)        t  =  undefined        if  a  <  b            t  =  b            b  =  a            a  =  t        while  b  isnt  0            t  =  b            b  =  a  %  b            a  =  t        this["gcd"]  =  -­‐>  a        return  a      lcm:  -­‐>        lcm  =  @a  /  @gcd()  *  @b        @lcm  =  -­‐>  lcm        return  lcm      toString:  -­‐>        "LCMCalculator:  a  =  #{@a},  b  =  #{@b}" output  =  (x)  -­‐>    document.body.appendChild  document.createTextNode(x)    document.body.appendChild  document.createElement("br")   [[25,  55],  [21,  56],  [22,  58],  [28,  56]].map((pair)  -­‐>    new  LCMCalculator(pair[0],  pair[1]) ).sort((a,  b)  -­‐>    a.lcm()  -­‐  b.lcm() ).forEach  (obj)  -­‐>    output  "obj  #{gcd}  =  #{obj.gcd()},  lcm  =  #{obj.lcm()}" Friday, June 7, 13
  • 18. “A little language that compiles into JavaScript.” What is CoffeeScript? Friday, June 7, 13
  • 19. “A little language that compiles into JavaScript.” Easily integrates with your current JavaScript What is CoffeeScript? Friday, June 7, 13
  • 20. “A little language that compiles into JavaScript.” Easily integrates with your current JavaScript Easier to read, write, maintain, refactor, etc... What is CoffeeScript? Friday, June 7, 13
  • 21. “A little language that compiles into JavaScript.” Easily integrates with your current JavaScript Easier to read, write, maintain, refactor, etc... A Hybrid languages like Ruby and Python. What is CoffeeScript? Friday, June 7, 13
  • 22. “A little language that compiles into JavaScript.” Easily integrates with your current JavaScript Easier to read, write, maintain, refactor, etc... A Hybrid languages like Ruby and Python. Helpful. What is CoffeeScript? Friday, June 7, 13
  • 23. Not Magic! Limited by what JavaScript can already do What CoffeeScript Is Not? Friday, June 7, 13
  • 24. “I’m happy writing JavaScript. I don’t need to learn another language.” Friday, June 7, 13
  • 25. FINE WITH ME Friday, June 7, 13
  • 28. .MODEL SMALL .STACK 64 .DATA VAL1 DB 01H VAL2 DB 01H LP DB 00H V1 DB 00H V2 DB 00H NL DB 0DH,0AH,'$' .CODE MAIN PROC MOV AX,@DATA MOV DS,AX MOV AH,01H INT 21H MOV CL,AL SUB CL,30H SUB CL,2 MOV AH,02H MOV DL,VAL1 ADD DL,30H INT 21H MOV AH,09H LEA DX,NL INT 21H MOV AH,02H MOV DL,VAL2 ADD DL,30H INT 21H MOV AH,09H LEA DX,NL INT 21H DISP: MOV BL,VAL1 ADD BL,VAL2 MOV AH,00H MOV AL,BL MOV LP,CL MOV CL,10 DIV CL MOV CL,LP MOV V1,AL MOV V2,AH MOV DL,V1 ADD DL,30H MOV AH,02H INT 21H MOV DL,V2 ADD DL,30H MOV AH,02H INT 21H MOV DL,VAL2 MOV VAL1,DL MOV VAL2,BL MOV AH,09H LEA DX,NL INT 21H LOOP DISP MOV AH,4CH INT 21H MAIN ENDP END MAIN Friday, June 7, 13
  • 29. .MODEL SMALL .STACK 64 .DATA VAL1 DB 01H VAL2 DB 01H LP DB 00H V1 DB 00H V2 DB 00H NL DB 0DH,0AH,'$' .CODE MAIN PROC MOV AX,@DATA MOV DS,AX MOV AH,01H INT 21H MOV CL,AL SUB CL,30H SUB CL,2 MOV AH,02H MOV DL,VAL1 ADD DL,30H INT 21H MOV AH,09H LEA DX,NL INT 21H MOV AH,02H MOV DL,VAL2 ADD DL,30H INT 21H MOV AH,09H LEA DX,NL INT 21H DISP: MOV BL,VAL1 ADD BL,VAL2 MOV AH,00H MOV AL,BL MOV LP,CL MOV CL,10 DIV CL MOV CL,LP MOV V1,AL MOV V2,AH MOV DL,V1 ADD DL,30H MOV AH,02H INT 21H MOV DL,V2 ADD DL,30H MOV AH,02H INT 21H MOV DL,VAL2 MOV VAL1,DL MOV VAL2,BL MOV AH,09H LEA DX,NL INT 21H LOOP DISP MOV AH,4CH INT 21H MAIN ENDP END MAIN Assembly Friday, June 7, 13
  • 30. #include <stdio.h> int fibonacci() { int n = 100; int a = 0; int b = 1; int sum; int i; for (i = 0; i < n; i++) { printf("%dn", a); sum = a + b; a = b; b = sum; } return 0; } C Friday, June 7, 13
  • 31. public static void fibonacci() { int n = 100; int a = 0; int b = 1; for (int i = 0; i < n; i++) { System.out.println(a); a = a + b; b = a - b; } } Java Friday, June 7, 13
  • 32. def fibonacci a = 0 b = 1 100.times do printf("%dn", a) a, b = b, a + b end end Ruby Friday, June 7, 13
  • 33. “I can write an app just as well in Java as I can in Ruby, but damn it if Ruby isn’t nicer to read and write!” Friday, June 7, 13
  • 36. $(function() { success = function(data) { if (data.errors != null) { alert("There was an error!"); } else { $("#content").text(data.message); } }; $.get('/users', success, 'json'); }); $ -> success = (data) -> if data.errors? alert "There was an error!" else $("#content").text(data.message) $.get('/users', success, 'json') JavaScript CoffeeScript Friday, June 7, 13
  • 37. Syntax Rules No semi-colons (ever!) No curly braces* No ‘function’ keyword Relaxed parentheses Whitespace significant formatting Friday, June 7, 13
  • 38. # Not required without arguments: noArg1 = -> # do something # Not required without arguments: noArg2 = () -> # do something # Required with Arguments: withArg = (arg) -> # do something Parentheses Rules # Required without arguments: noArg1() noArg2() # Not required with arguments: withArg("bar") withArg "bar" Friday, June 7, 13
  • 39. # Bad: $ "#some_id" .text() # $("#some_id".text()); # Good: $("#some_id").text() # $("#some_id").text(); Parentheses Rules Friday, June 7, 13
  • 41. Whitespace $(function() { success = function(data) { if (data.errors != null) { alert("There was an error!"); } else { $("#content").text(data.message); } }; $.get('/users', success, 'json'); }); Friday, June 7, 13
  • 42. Whitespace $(function() { success = function(data) { if (data.errors != null) { alert("There was an error!"); } else { $("#content").text(data.message); } }; $.get('/users', success, 'json'); }); Friday, June 7, 13
  • 43. Whitespace $ -> success = (data) -> if data.errors? alert "There was an error!" else $("#content").text(data.message) $.get('/users', success, 'json') Friday, June 7, 13
  • 44. Conditionals doSomething() if true doSomething() unless true if true doSomething() unless true doSomething() if true doSomething() else doSomethingElse() Friday, June 7, 13
  • 45. Objects/Hashes someObject = {conf: "FluentConf", talk: "CoffeeScript"} someObject = conf: "FluentConf" talk: "CoffeeScript" someFunction(conf: "FluentConf", talk: "CoffeeScript") Friday, June 7, 13
  • 46. Objects/Hashes var someObject; someObject = { conf: "FluentConf", talk: "CoffeeScript" }; someObject = { conf: "FluentConf", talk: "CoffeeScript" }; someFunction({ conf: "FluentConf", talk: "CoffeeScript" }); Friday, June 7, 13
  • 47. String Interpolation name = "FluentConf 2013" console.log "Hello #{name}" # Hello FluentConf 2013 console.log 'Hello #{name}' # Hello #{name} Friday, June 7, 13
  • 48. String Interpolation name = "FluentConf 2013" console.log "Hello #{name}" # Hello FluentConf 2013 console.log 'Hello #{name}' # Hello #{name} var name; name = "FluentConf 2013"; console.log("Hello " + name); console.log('Hello #{name}'); Friday, June 7, 13
  • 49. Heredocs html = """ <div class="comment" id="tweet-#{tweet.id_str}"> <hr> <div class='tweet'> <span class="imgr"><img src="#{tweet.profile_image_url}"></span> <span class="txtr"> <h5><a href="http://twitter.com/#{tweet.from_user}" target="_blank">@#{tweet.from_user}</a></h5> <p>#{tweet.text}</p> <p class="comment-posted-on">#{tweet.created_at}</p> </span> </div> </div> """ Friday, June 7, 13
  • 50. Heredocs var html; html = "<div class="comment" id="tweet-" + tweet.id_str + "">n <hr>n <div class='tweet'>n <span class= "imgr"><img src="" + tweet.profile_image_url + ""></ span>n <span class="txtr">n <h5><a href= "http://twitter.com/" + tweet.from_user + "" target= "_blank">@" + tweet.from_user + "</a></h5>n <p>" + tweet.text + "</p>n <p class="comment-posted-on">" + tweet.created_at + "</p>n </span>n </div>n</div>"; Friday, June 7, 13
  • 51. Functions p = (name) -> console.log "Hello #{name}" p('FluentConf 2013') Friday, June 7, 13
  • 52. Functions var p; p = function(name) { return console.log("Hello " + name); }; p('FluentConf 2013'); Friday, June 7, 13
  • 53. Loops & Comprehensions for someName in someArray console.log someName for key, value of someObject console.log "#{key}: #{value}" Friday, June 7, 13
  • 54. Loops & Comprehensions var key, someName, value, _i, _len; for (_i = 0, _len = someArray.length; _i < _len; _i++) { someName = someArray[_i]; console.log(someName); } for (key in someObject) { value = someObject[key]; console.log("" + key + ": " + value); } Friday, June 7, 13
  • 55. Loops & Comprehensions numbers = [1..5] console.log number for number in numbers Friday, June 7, 13
  • 56. Loops & Comprehensions var number, numbers, _i, _len; numbers = [1, 2, 3, 4, 5]; for (_i = 0, _len = numbers.length; _i < _len; _i++) { number = numbers[_i]; console.log(number); } Friday, June 7, 13
  • 57. Loops & Comprehensions numbers = [1..5] console.log number for number in numbers when number <= 3 Friday, June 7, 13
  • 58. Loops & Comprehensions var number, numbers, _i, _len; numbers = [1, 2, 3, 4, 5]; for (_i = 0, _len = numbers.length; _i < _len; _i++) { number = numbers[_i]; if (number <= 3) { console.log(number); } } Friday, June 7, 13
  • 59. Loops & Comprehensions numbers = [1, 2, 3, 4, 5] low_numbers = (number * 2 for number in numbers when number <= 3) console.log low_numbers # [ 2, 4, 6 ] Friday, June 7, 13
  • 60. Loops & Comprehensions var low_numbers, number, numbers; numbers = [1, 2, 3, 4, 5]; low_numbers = (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = numbers.length; _i < _len; _i++) { number = numbers[_i]; if (number <= 3) { _results.push(number * 2); } } return _results; })(); console.log(low_numbers); Friday, June 7, 13
  • 61. Classes class Employee emp = new Employee() emp.firstName = "Mark" Friday, June 7, 13
  • 62. Classes var Employee, emp; Employee = (function() { Employee.name = 'Employee'; function Employee() {} return Employee; })(); emp = new Employee(); emp.firstName = "Mark"; Friday, June 7, 13
  • 63. Classes class Employee constructor: (@options = {}) -> salary: -> @options.salary ?= "$250,000" emp = new Employee() console.log emp.salary() # "$250,000" emp = new Employee(salary: "$100,000") console.log emp.salary() # "$100,000" Friday, June 7, 13
  • 64. Classes var Employee, emp; Employee = (function() { Employee.name = 'Employee'; function Employee(options) { this.options = options != null ? options : {}; } Employee.prototype.salary = function() { var _base, _ref; return (_ref = (_base = this.options).salary) != null ? _ref : _base.salary = "$250,000"; }; return Employee; })(); emp = new Employee(); console.log(emp.salary()); emp = new Employee({ salary: "$100,000" }); console.log(emp.salary()); Friday, June 7, 13
  • 65. Extending Classes class Manager extends Employee salary: -> "#{super} w/ $10k Bonus" manager = new Manager() console.log manager.salary() # "$250,000 w/ $10k Bonus" Friday, June 7, 13
  • 66. Extending Classes var Manager, manager, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; Manager = (function(_super) { __extends(Manager, _super); Manager.name = 'Manager'; function Manager() { var _base; Manager.__super__.constructor.apply(this, arguments); } Manager.prototype.salary = function() { return "" + Manager.__super__.salary.apply(this, arguments) + " w/ $10k Bonus"; }; return Manager; })(Employee); manager = new Manager(); console.log(manager.salary()); Friday, June 7, 13
  • 67. Bound Functions class User constructor: (@name) -> sayHi: -> console.log "Hello #{@name}" bob = new User('bob') mary = new User('mary') log = (callback)-> console.log "about to execute callback..." callback() console.log "...executed callback" log(bob.sayHi) log(mary.sayHi) Friday, June 7, 13
  • 68. Bound Functions about to execute callback... Hello undefined ...executed callback about to execute callback... Hello undefined ...executed callback Friday, June 7, 13
  • 69. class User constructor: (@name) -> sayHi: -> console.log "Hello #{@name}" bob = new User('bob') mary = new User('mary') log = (callback)-> console.log "about to execute callback..." callback() console.log "...executed callback" log(bob.sayHi) log(mary.sayHi) Bound Functions Friday, June 7, 13
  • 70. class User constructor: (@name) -> sayHi: -> console.log "Hello #{@name}" bob = new User('bob') mary = new User('mary') log = (callback)-> console.log "about to execute callback..." callback() console.log "...executed callback" log(bob.sayHi) log(mary.sayHi) Bound Functions Friday, June 7, 13
  • 71. class User constructor: (@name) -> sayHi: => console.log "Hello #{@name}" bob = new User('bob') mary = new User('mary') log = (callback)-> console.log "about to execute callback..." callback() console.log "...executed callback" log(bob.sayHi) log(mary.sayHi) Bound Functions Friday, June 7, 13
  • 72. Bound Functions about to execute callback... Hello bob ...executed callback about to execute callback... Hello mary ...executed callback Friday, June 7, 13
  • 73. Bound Functions class User constructor: (@name) -> sayHi: => console.log "Hello #{@name}" Friday, June 7, 13
  • 74. Bound Functions var User, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; User = (function() { User.name = 'User'; function User(name) { this.name = name; this.sayHi = __bind(this.sayHi, this); } User.prototype.sayHi = function() { return console.log("Hello " + this.name); }; return User; })(); Friday, June 7, 13
  • 75. FINALLY One of my favorite features Friday, June 7, 13
  • 76. Existential Operator if foo? console.log "foo" Friday, June 7, 13
  • 77. Existential Operator if (typeof foo !== "undefined" && foo !== null) { console.log("foo"); } Friday, June 7, 13
  • 80. Existential Operator console?.log "foo" if (typeof console !== "undefined" && console !== null) { console.log("foo"); } Friday, June 7, 13
  • 81. Existential Operator if currentUser?.firstName? console.log currentUser.firstName Friday, June 7, 13
  • 82. Existential Operator if currentUser?.firstName? console.log currentUser.firstName if ((typeof currentUser !== "undefined" && currentUser !== null ? currentUser.firstName : void 0) != null) { console.log(currentUser.firstName); } Friday, June 7, 13
  • 85. Once upon a mignight dreary while I pondered, weak and weary, Over many quaint and curious volume of forgotten lore - While I nodded, nearly napping, suddenly there came a tapping, As of some one gently rapping, rapping at my chamber door "'Tis some visiter". I muttered, "tapping at my chamber door" - "only this and nothing more." Ah distinctly I remember it was in the bleak December; And each separate dying ember wrought its ghost upon the floor. Eagerly I wished the morrow - vainly I had sought to borrow, From my books surcease of sorrow - sorrow For the lost Lenore - For the rare and radiant maiden whom the angels name Lenore - Nameless here For evermore The Raven Friday, June 7, 13
  • 86. The Raven var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; while (I(pondered, weak && weary, Over(many(quaint && curious(volume in forgotten(lore - While(I(nodded, nearly(napping, suddenly(there(came(a(tapping, As in some(one(gently(rapping, rapping(at(my(chamber(door)))))))))))))))))))) {   Once(upon(a(mignight(dreary)))); } "'Tis some visiter".I(muttered, "tapping at my chamber door" - "only this and nothing more."); Ah(distinctly(I(remember(it(__indexOf.call(the(bleak(December)), was) >= 0))))); And(each(separate(dying(ember(wrought(its(ghost(upon(the(floor.Eagerly(I(wished( the(morrow - vainly(I(had(sought(to(borrow, From(my(books(surcease in sorrow - sorrow(For(the(lost(Lenore - For(the(rare && radiant(maiden(whom(the(angels(name(Lenore - Nameless(here(For(evermore))))))))))))))))))))))))))))))))))))); Friday, June 7, 13
  • 87. What Didn’t I Cover? Default Arguments Ranges Splatted Arguments Scoping Security Strict Mode Fixes common ‘mistakes’ Operators The `do` keyword Source Maps Plenty more! Friday, June 7, 13
  • 89. Thank you! myName = "Mark Bates" you.should buyBook("Programming in CoffeeScript") .at("http://books.markbates.com") you.should follow(@markbates) Friday, June 7, 13