SlideShare a Scribd company logo
1 of 215
Let’s Have a Cup of
JavaScript
me = {
  name: “Nicolás”,
  location: “Montevideo, Uruguay”,
  age: 26,
  likesWorkingOn: [“Ruby”, “JavaScript”],
  twitter: “@godfoca”,
  github: “http://github.com/foca”,
  url: “http://nicolassanguinetti.info”,
  company: {
    name: “Cubox”,
    url: “http://cuboxsa.com”
  }
}
me = {
  name: “Nicolás”,
  location: “Montevideo, Uruguay
  age: 26,
  likesWorkingOn: [“Ruby”, “Java
  twitter: “@godfoca”,
  github: “http://github.com/foc
  url: “http://nicolassanguinett
  company: {
    name: “Cubox”,
    url: “http://cuboxsa.com”
me = {
  name: “Nicolás”,
  location: “Montevid
  age: 26,
  likesWorkingOn: [“R
  twitter: “@godfoca”
  github: “http://git
me = {
  name: “Nicolás”
  location: “Mont
  age: 26,
  likesWorkingOn:
  twitter: “@godf
There’s no var
me = {
  name: “Nico
  location:
  age: 26,
me = {
  name: “Nicolás”,
  location: “Montevideo, Uruguay”,
  age: 26,
  likesWorkingOn: [“Ruby”, “JavaScript”],
  twitter: “@godfoca”,
  github: “http://github.com/foca”,
  url: “http://nicolassanguinetti.info”,
  company: {
    name: “Cubox”,
    url: “http://cuboxsa.com”
  }
}
me = {
  name: “Nicolás”,
  location: “Montevideo, Uruguay”,
  age: 26,
  likesWorkingOn: [“Ruby”, “JavaScript”],
  twitter: “@godfoca”,
  github: “http://github.com/foca”,
  url: “http://nicolassanguinetti.info”,
  company: {
    name: “Cubox”,
    url: “http://cuboxsa.com”
  }
}
me =
  name: “Nicolás”,
  location: “Montevideo, Uruguay”,
  age: 26,
  likesWorkingOn: [“Ruby”, “JavaScript”],
  twitter: “@godfoca”,
  github: “http://github.com/foca”,
  url: “http://nicolassanguinetti.info”,
  company:
     name: “Cubox”,
     url: “http://cuboxsa.com”
me =
  name: “Nicolás”,
  location: “Montevideo, Uruguay”,
  age: 26,
  likesWorkingOn: [“Ruby”, “JavaScript”],
  twitter: “@godfoca”,
  github: “http://github.com/foca”,
  url: “http://nicolassanguinetti.info”,
  company:
     name: “Cubox”,
     url: “http://cuboxsa.com”
me =
  name: “Nicolás”,
  location: “Montevideo, Uruguay”,
  age: 26,
  likesWorkingOn: [“Ruby”, “JavaScript”],
  twitter: “@godfoca”,
  github: “http://github.com/foca”,
  url: “http://nicolassanguinetti.info”,
  company:
     name: “Cubox”,
     url: “http://cuboxsa.com”
me =
  name: “Nicolás”
  location: “Montevideo, Uruguay”
  age: 26
  likesWorkingOn: [“Ruby”, “JavaScript”]
  twitter: “@godfoca”
  github: “http://github.com/foca”
  url: “http://nicolassanguinetti.info”
  company:
     name: “Cubox”
     url: “http://cuboxsa.com”
me =
  name: “Nicolás”
  location: “Montevideo, Uruguay”
  age: 26
  likesWorkingOn: [“Ruby”, “JavaScript”]
  twitter: “@godfoca”
  github: “http://github.com/foca”
  url: “http://nicolassanguinetti.info”
  company:
     name: “Cubox”
     url: “http://cuboxsa.com”
Let’s Have a few Cups of
1st Cup
A simple comparison
1st Cup: A simple comparison

var square = function(num) {
  return num * num;
}
var list = [1, 2, 3, 4, 5];
var squares = [];
for (var i = 0; i < list.length; i++) {
  squares.push(square(list[i]));
}
1st Cup: A simple comparison

var square = function(num) {
  return num * num;
}
var list = [1, 2, 3, 4, 5];
var squares = [];
for (var i = 0; i < list.length; i++) {
  squares.push(square(list[i]));
}
1st Cup: A simple comparison

var square = function(num) {
  return num * num;
}
var list = [1, 2, 3, 4, 5];
var squares = [];
for (var i = 0; i < list.length; i++) {
  squares.push(square(list[i]));
}
1st Cup: A simple comparison

var square = function(num) {
  return num * num;
}
var list = [1, 2, 3, 4, 5];
var squares = [];
for (var i = 0; i < list.length; i++) {
  squares.push(square(list[i]));
}
1st Cup: A simple comparison

var square = function(num) {
  return num * num;
}
var list = [1, 2, 3, 4, 5];
var squares = [];
for (var i = 0; i < list.length; i++) {
  squares.push(square(list[i]));
}
1st Cup: A simple comparison



square = (num) -> num * num
list = [1..5]
squares = (square n for n in list)
1st Cup: A simple comparison



square = (num) -> num * num
list = [1..5]
squares = (square n for n in list)
1st Cup: A simple comparison



square = (num) -> num * num
list = [1..5]
squares = (square n for n in list)
1st Cup: A simple comparison



square = (num) -> num * num
list = [1..5]
squares = (square n for n in list)
1st Cup: A simple comparison



square = (num) -> num * num
list = [1..5]
squares = (square n for n in list)
2nd Cup
The Useless Calculator
2nd Cup: The Useless Calculator

var add = function(num1, num2) {
  return num1 + “ + “ + num2 +
    “ = “ + (num1 + num2);
}

console.log(add(2, 3))
> 2 + 3 = 5
console.log(add(5, 7))
> 5 + 7 = 12
2nd Cup: The Useless Calculator

var add = function(num1, num2) {
  return num1 + “ + “ + num2 +
    “ = “ + (num1 + num2);
}

console.log(add(2, 3))
> 2 + 3 = 5
console.log(add(5, 7))
> 5 + 7 = 12
2nd Cup: The Useless Calculator

var add = function(num1, num2) {
  return num1 + “ + “ + num2 +
    “ = “ + (num1 + num2);
}

console.log(add(2, 3))
> 2 + 3 = 5
console.log(add(5, 7))
> 5 + 7 = 12
2nd Cup: The Useless Calculator

var add = function(num1, num2) {
  return num1 + “ + “ + num2 +
    “ = “ + (num1 + num2);
}

console.log(add(2, 3))
> 2 + 3 = 5
console.log(add(5, 7))
> 5 + 7 = 12
2nd Cup: The Useless Calculator

var add = function(num1, num2) {
  return num1 + “ + “ + num2 +
    “ = “ + (num1 + num2);
}

console.log(add(2, 3))
> 2 + 3 = 5
console.log(add(5, 7))
> 5 + 7 = 12
2nd Cup: The Useless Calculator


add = (num1, num2) ->
  “#{num1} + #{num2} = #{num1 + num2}”

console.log add(2, 3)
> 2 + 3 = 5
console.log add(5, 7)
> 5 + 7 = 12
2nd Cup: The Useless Calculator


add = (num1, num2) ->
  “#{num1} + #{num2} = #{num1 + num2}”

console.log add(2, 3)
> 2 + 3 = 5
console.log add(5, 7)
> 5 + 7 = 12
2nd Cup: The Useless Calculator


add = (num1, num2) ->
  “#{num1} + #{num2} = #{num1 + num2}”

console.log add(2, 3)
> 2 + 3 = 5
console.log add(5, 7)
> 5 + 7 = 12
2nd Cup: The Useless Calculator


add = (num1, num2) ->
  “#{num1} + #{num2} = #{num1 + num2}”

console.log add(2, 3)
> 2 + 3 = 5
console.log add(5, 7)
> 5 + 7 = 12
2nd Cup: The Useless Calculator


add = (num1, num2) ->
  “#{num1} + #{num2} = #{num1 + num2}”

console.log add(2, 3)
> 2 + 3 = 5
console.log add(5, 7)
> 5 + 7 = 12
3rd Cup
Your Favorite Language
3rd Cup: Your Favorite Language


languageOfChoice = (lang) ->
  “#{lang} rocks!”
3rd Cup: Your Favorite Language


languageOfChoice = (lang) ->
  “#{lang} rocks!”

console.log languageOfChoice(“Ruby”)
> Ruby rocks!
3rd Cup: Your Favorite Language
           Implicit Return


languageOfChoice = (lang) ->
  “#{lang} rocks!”
3rd Cup: Your Favorite Language
           Implicit Return

languageOfChoice = (lang) ->
  return “#{lang} rocks!”
3rd Cup: Your Favorite Language
           Implicit Return

languageOfChoice = (lang) ->
  if lang == “PHP”
    “Get outta here!”
  else
    “#{lang} rocks!”
3rd Cup: Your Favorite Language
           Implicit Return

languageOfChoice = (lang) ->
  if lang == “PHP”
    return “Get outta here!”
  else
    return “#{lang} rocks!”
3rd Cup: Your Favorite Language
          Default Arguments

languageOfChoice = (lang = “Ruby”) ->
  “#{lang} rocks!”
3rd Cup: Your Favorite Language
          Default Arguments

languageOfChoice = (lang = “Ruby”) ->
  “#{lang} rocks!”

console.log languageOfChoice(“Lua”)
> Lua rocks!
3rd Cup: Your Favorite Language
          Default Arguments

languageOfChoice = (lang = “Ruby”) ->
  “#{lang} rocks!”

console.log languageOfChoice(“Lua”)
> Lua rocks!
console.log languageOfChoice()
> Ruby rocks!
3rd Cup: Your Favorite Language
         Optional Parentheses

languageOfChoice = (lang = “Ruby”) ->
  “#{lang} rocks!”
3rd Cup: Your Favorite Language
         Optional Parentheses

languageOfChoice = (lang = “Ruby”) ->
  “#{lang} rocks!”

console.log languageOfChoice “Lua”
> Lua rocks!
3rd Cup: Your Favorite Language
         Optional Parentheses

languageOfChoice = (lang = “Ruby”) ->
  “#{lang} rocks!”

console.log languageOfChoice “Lua”
> Lua rocks!
console.log languageOfChoice
3rd Cup: Your Favorite Language
         Optional Parentheses

languageOfChoice = (lang = “Ruby”) ->
  “#{lang} rocks!”

console.log languageOfChoice “Lua”
> Lua rocks!
console.log languageOfChoice
> [function “languageOfChoice”]
3rd Cup: Your Favorite Language
         Optional Parentheses

languageOfChoice = (lang = “Ruby”) ->
  “#{lang} rocks!”

console.log languageOfChoice “Lua”
> Lua rocks!
console.log languageOfChoice
> [function “languageOfChoice”]
console.log languageOfChoice()
> Ruby rocks!
3rd Cup: Your Favorite Language
                 Splats

languagesOfChoice = (langs...) ->
  “I like #{langs.join(“, “)}”
3rd Cup: Your Favorite Language
                 Splats

languagesOfChoice = (langs...) ->
  “I like #{langs.join(“, “)}”

languagesOfChoice “Ruby”, “JS”, “Python”
> I like Ruby, JS, Python
3rd Cup: Your Favorite Language
                 Splats

myLangs = [“Ruby”, “JS”, “Python”]
3rd Cup: Your Favorite Language
                 Splats

myLangs = [“Ruby”, “JS”, “Python”]

languagesOfChoice myLangs...
> I like Ruby, JS, Python
3rd Cup: Your Favorite Language
                 Splats

languagesOfChoice = (best, langs...) ->
  “I love #{best},
  and I like #{langs.join(“, “)}”
3rd Cup: Your Favorite Language
                 Splats

languagesOfChoice = (best, langs...) ->
  “I love #{best},
  and I like #{langs.join(“, “)}”

languagesOfChoice “Ruby”, “JS”, “Python”
> I love Ruby, and I like JS, Python
3rd Cup: Your Favorite Language
                 Splats

languagesOfChoice = (langs..., worst) ->
  “I like #{langs.join(“, “)},
  but I hate #{worst}”
3rd Cup: Your Favorite Language
                 Splats

languagesOfChoice = (langs..., worst) ->
  “I like #{langs.join(“, “)},
  but I hate #{worst}”

languagesOfChoice “Ruby”, “JS”, “PHP”
> I like Ruby, JS, but I hate PHP
3rd Cup: Your Favorite Language
           Existential Operator

languagesOfChoice = (best, langs...) ->
  “I love #{best},
  and I like #{langs.join(“, “)}”
3rd Cup: Your Favorite Language
           Existential Operator

languagesOfChoice = (best, langs...) ->
  “I love #{best},
  and I like #{langs.join(“, “)}”

languagesOfChoice “Ruby”
> I love Ruby, and I like
3rd Cup: Your Favorite Language
           Existential Operator

languagesOfChoice = (best, langs...) ->
  “I love #{best},
  and I like #{langs.join(“, “)}”

languagesOfChoice “Ruby”
> I love Ruby, and I like
languagesOfChoice()
> I love , and I like
3rd Cup: Your Favorite Language
           Existential Operator

languagesOfChoice = (best, langs...) ->
  ret = []
  if best?
    ret.push “I love #{best}”
  if langs.length > 0
    ret.push “I like #{langs.join(“, “)}”
  ret.join(“, and “)
3rd Cup: Your Favorite Language
           Existential Operator

languagesOfChoice = (best, langs...) ->
  ret = []
  if best?
    ret.push “I love #{best}”
  if langs.length > 0
    ret.push “I like #{langs.join(“, “)}”
  ret.join(“, and “)
3rd Cup: Your Favorite Language
           Existential Operator

languagesOfChoice = (best, langs...) ->
  ret = []
  if best?
    ret.push “I love #{best}”
  if langs.length > 0
    ret.push “I like #{langs.join(“, “)}”
  ret.join(“, and “)
3rd Cup: Your Favorite Language
           Existential Operator

languagesOfChoice = (best, langs...) ->
  ret = []
  if best?
    ret.push “I love #{best}”
  if langs.length > 0
    ret.push “I like #{langs.join(“, “)}”
  ret.join(“, and “)
3rd Cup: Your Favorite Language
           Existential Operator

languagesOfChoice = (best, langs...) ->
  ret = []
  if best?
    ret.push “I love #{best}”
  if langs.length > 0
    ret.push “I like #{langs.join(“, “)}”
  ret.join(“, and “)
3rd Cup: Your Favorite Language
           Existential Operator

languagesOfChoice “Ruby”, “JS”, “Python”
> I love Ruby, and I like JS, Python
3rd Cup: Your Favorite Language
           Existential Operator

languagesOfChoice “Ruby”, “JS”, “Python”
> I love Ruby, and I like JS, Python
languagesOfChoice “Ruby”
> I love Ruby
3rd Cup: Your Favorite Language
           Existential Operator

languagesOfChoice “Ruby”, “JS”, “Python”
> I love Ruby, and I like JS, Python
languagesOfChoice “Ruby”
> I love Ruby
languagesOfChoice undefined, “Ruby”, “JS”
> I like Ruby, JS
3rd Cup: Your Favorite Language
           Existential Operator

languagesOfChoice “Ruby”, “JS”, “Python”
> I love Ruby, and I like JS, Python
languagesOfChoice “Ruby”
> I love Ruby
languagesOfChoice undefined, “Ruby”, “JS”
> I like Ruby, JS
languagesOfChoice()
> “”
3rd Cup: Your Favorite Language
        Existential Operator



               expr?
3rd Cup: Your Favorite Language
            Existential Operator



                   expr?

typeof expr !== undefined && expr !== null
3rd Cup: Your Favorite Language
        Existential Operator



              x ?= y
3rd Cup: Your Favorite Language
        Existential Operator



              x ?= y

         x = y unless x?
3rd Cup: Your Favorite Language
        Existential Operator



        obj = x: { y: 2 }
3rd Cup: Your Favorite Language
        Existential Operator



        obj = x: { y: 2 }

             obj.x?.y
3rd Cup: Your Favorite Language
          Existential Operator



          obj = x: { y: 2 }

               obj.x?.y

if obj.x? then obj.x.y else undefined
3rd Cup: Your Favorite Language
          Existential Operator



          obj = x: { y: 2 }

               obj.x?.y

if obj.x? then obj.x.y else undefined
3rd Cup: Your Favorite Language
          Existential Operator



          obj = x: { y: 2 }

               obj.x?.y

if obj.x? then obj.x.y else undefined
3rd Cup: Your Favorite Language
          Existential Operator



          obj = x: { y: 2 }

               obj.x?.y

if obj.x? then obj.x.y else undefined
3rd Cup: Your Favorite Language
        Existential Operator



             func?()
3rd Cup: Your Favorite Language
         Existential Operator



              func?()

func() if typeof func == “function”
3rd Cup: Your Favorite Language
        Existential Operator




       options.callback?()
Interlude
  Ranges
Interlude: Ranges




[1..5]   #=> [1, 2, 3, 4, 5]
Interlude: Ranges




[1..5] #=> [1, 2, 3, 4, 5]
[1...5] #=> [1, 2, 3, 4]
Interlude: Ranges



list = [1, 2, 3, 4, 5]
list[2..3] #=> [3, 4]
Interlude: Ranges



list = [1, 2, 3, 4, 5]
list[2..-1] #=> [3, 4, 5]
4th Cup
 Patterns
4th Cup: Patterns


list = [“Ruby”, “JS”, “Python”]
4th Cup: Patterns


list = [“Ruby”, “JS”, “Python”]

     Head            Tail
4th Cup: Patterns


list = [“Ruby”, “JS”, “Python”]

head = list[0]
tail = list[1..-1]
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[head, tail] = [list[0], list[1..-1]]
4th Cup: Patterns
              Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[head, tail] = [list[0], list[1..-1]]


  Pattern
4th Cup: Patterns
              Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[head, tail] = [list[0], list[1..-1]]


  Pattern                 Values
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[head, tail] = [list[0], list[1..-1]]
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[head, tail] = [list[0], list[1..-1]]
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[head, tail] = [list[0], list[1..-1]]

head #=> “Ruby”
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[head, tail] = [list[0], list[1..-1]]

head #=> “Ruby”
tail #=> [“JS”, “Python”]
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[head, tail...] = list
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[head, tail...] = list
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[head, tail...] = list

head #=> “Ruby”
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[head, tail...] = list

head #=> “Ruby”
tail #=> [“JS”, “Python”]
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[top, rest..., bottom] = list
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[top, rest..., bottom] = list

top #=> “Ruby”
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[top, rest..., bottom] = list

top #=> “Ruby”
bottom #=> “Python”
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”, “Python”]
[top, rest..., bottom] = list

top #=> “Ruby”
bottom #=> “Python”
rest #=> [“JS”]
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”]
[top, rest..., bottom] = list
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”]
[top, rest..., bottom] = list

top #=> “Ruby”
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”]
[top, rest..., bottom] = list

top #=> “Ruby”
bottom #=> “JS”
4th Cup: Patterns
           Pattern Matching


list = [“Ruby”, “JS”]
[top, rest..., bottom] = list

top #=> “Ruby”
bottom #=> “JS”
rest #=> []
4th Cup: Patterns
            Pattern Matching
me =
  name: “Nicolás”
  age: 26
  company:
     name: “Cubox”
4th Cup: Patterns
            Pattern Matching
me =
  name: “Nicolás”
  age: 26
  company:
     name: “Cubox”

name = me.name
age = me.age
4th Cup: Patterns
            Pattern Matching
me =
  name: “Nicolás”
  age: 26
  company:
     name: “Cubox”

{ name: name, age: age } = me
4th Cup: Patterns
             Pattern Matching
me =
  name: “Nicolás”
  age: 26
  company:
     name: “Cubox”

{ name: name, age: age } = me

       Pattern
4th Cup: Patterns
             Pattern Matching
me =
  name: “Nicolás”
  age: 26
  company:
     name: “Cubox”

{ name: name, age: age } = me

            Variables
4th Cup: Patterns
            Pattern Matching
me =
  name: “Nicolás”
  age: 26
  company:
     name: “Cubox”

{ name: name, age: age } = me

                     Values
4th Cup: Patterns
            Pattern Matching
me =
  name: “Nicolás”
  age: 26
  company:
     name: “Cubox”

{ name: name, age: age } = me

name #=> “Nicolás”
age #=> 26
4th Cup: Patterns
          Pattern Matching



{ name, age } = me
4th Cup: Patterns
          Pattern Matching



{ name, age } = me

name #=> “Nicolás”
4th Cup: Patterns
          Pattern Matching



{ name, age } = me

name #=> “Nicolás”
age #=> 26
5th Cup
Collecting Collections
5th Cup: Collecting Collections
          Iterating over arrays



list = [1..10]

for item in list
  doSomethingWith(item)
5th Cup: Collecting Collections
          Iterating over arrays



list = [1..10]

for item in list
  doSomethingWith(item)
5th Cup: Collecting Collections
          Iterating over objects



me = name: “Nicolás”, age: 26

for key, value of me
  console.log “#{key}: #{value}”
5th Cup: Collecting Collections
          Iterating over objects



me = name: “Nicolás”, age: 26

for key, value of me
  console.log “#{key}: #{value}”
5th Cup: Collecting Collections
         Comprehensions



alert n for n in [1..5]
5th Cup: Collecting Collections
         Comprehensions



alert n for n in [1..5]
5th Cup: Collecting Collections
           Comprehensions



doubles = (n * 2 for n in [1..5])
5th Cup: Collecting Collections
      Filtering Comprehensions



alert n for n in [1..5] when n > 2
5th Cup: Collecting Collections
      Filtering Comprehensions



alert n for n in [1..5] when n > 2
5th Cup: Collecting Collections
      Filtering Comprehensions



alert n for n in [1..5] when n > 2

for n in [1..5]
  continue unless n > 2
  alert n
5th Cup: Collecting Collections
      Filtering Comprehensions



alert n for n in [1..5] when n > 2

for n in [1..5]
  continue unless n > 2
  alert n
Interlude
   this
Interlude: this



function isCute() {
  return this.cute;
}
Interlude: this



       var cuteKitty = {
         cute: true,
         isCute: isCute
       };
Interlude: this



       var meanKitty = {
         cute: false,
         isCute: isCute
       };
Interlude: this




cuteKitty.isCute()   meanKitty.isCute()
Interlude: this




cuteKitty.isCute()   meanKitty.isCute()
       true
Interlude: this




cuteKitty.isCute()   meanKitty.isCute()
       true                 false
Interlude: this


function whatHappensNow() {
  console.log(this);
}

whatHappensNow()
Interlude: this


function whatHappensNow() {
  console.log(this);
}

whatHappensNow()
> [window]
Interlude: this



$(“a.sign-out”).click(function() {
  console.log(this);
});
Interlude: this



$(“a.sign-out”).click(function() {
  console.log(this);
});
Interlude: this



$(“a.sign-out”).click(function() {
  console.log(this);
});

<a href=”#” class=”delete”>Delete</a>
Interlude: this


function returnThis() {
  return this;
}
Interlude: this


function returnThis() {
  return this;
}

returnThis.apply(42);     //=> 42
Interlude: this


function returnThis() {
  return this;
}

returnThis.apply(42);   //=> 42
returnThis.apply(“hi”); //=> “hi”
6th Cup
Context, the classy way
6th Cup: Context, the classy way

User = (id, name) ->
  this.id = id
  this.name = name
  this.element = $(“#user-#{this.id}”)
6th Cup: Context, the classy way
            Context Accessor

User = (id, name) ->
  this.id = id
  this.name = name
  this.element = $(“#user-#{this.id}”)
6th Cup: Context, the classy way
            Context Accessor

User = (id, name) ->
  this.id = id
  this.name = name
  this.element = $(“#user-#{this.id}”)
6th Cup: Context, the classy way
            Context Accessor

User = (id, name) ->
  this.id = id
  this.name = name
  this.element = $(“#user-#{this.id}”)
6th Cup: Context, the classy way
            Context Accessor

User = (id, name) ->
  this.id = id
  this.name = name
  this.element = $(“#user-#{this.id}”)
6th Cup: Context, the classy way
            Context Accessor

User = (id, name) ->
  @id = id
  @name = name
  @element = $(“#user-#{@id}”)
6th Cup: Context, the classy way
          Property Arguments

User = (id, name) ->
  @id = id
  @name = name
  @element = $(“#user-#{@id}”)
6th Cup: Context, the classy way
          Property Arguments

User = (id, name) ->
  @id = id
  @name = name
  @element = $(“#user-#{@id}”)
6th Cup: Context, the classy way
          Property Arguments

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)
6th Cup: Context, the classy way
          Property Arguments

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)
6th Cup: Context, the classy way
          Property Arguments

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)
6th Cup: Context, the classy way

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)
6th Cup: Context, the classy way
            Bound Functions

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)

User.prototype.signOut = ->
  $.ajax(...)
6th Cup: Context, the classy way
            Bound Functions

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)

User.prototype.signOut = ->
  $.ajax(...)
6th Cup: Context, the classy way
            Bound Functions

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)

User.prototype.signOut = ->
  $.ajax(...)
6th Cup: Context, the classy way
            Bound Functions

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)

 $(“a.sign-out”, @element).click ->
   this.signOut()
   false

User.prototype.signOut = ->
  $.ajax(...)
6th Cup: Context, the classy way
            Bound Functions

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)

 $(“a.sign-out”, @element).click ->
   this.signOut()
   false

User.prototype.signOut = ->
  $.ajax(...)
6th Cup: Context, the classy way
            Bound Functions

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)

 $(“a.sign-out”, @element).click ->
   this.signOut()
   false

User.prototype.signOut = ->
  $.ajax(...)
6th Cup: Context, the classy way
            Bound Functions

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)
  self = this

 $(“a.sign-out”, @element).click ->
   self.signOut()
   false

User.prototype.signOut = ->
  $.ajax(...)
6th Cup: Context, the classy way
            Bound Functions

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)
  self = this

 $(“a.sign-out”, @element).click ->
   self.signOut()
   false

User.prototype.signOut = ->
  $.ajax(...)
6th Cup: Context, the classy way
            Bound Functions

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)

 $(“a.sign-out”, @element).click =>
   this.signOut()
   false

User.prototype.signOut = ->
  $.ajax(...)
6th Cup: Context, the classy way
            Bound Functions

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)

 $(“a.sign-out”, @element).click =>
   this.signOut()
   false

User.prototype.signOut = ->
  $.ajax(...)
6th Cup: Context, the classy way
            Bound Functions

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)

 $(“a.sign-out”, @element).click =>
   this.signOut()
   false

User.prototype.signOut = ->
  $.ajax(...)
6th Cup: Context, the classy way

User = (@id, @name) ->
  @element = $(“#user-#{@id}”)

User.prototype.signOut = ->
  ...
6th Cup: Context, the classy way
                Classes

class User
  constructor: (@id, @name) ->
    @element = $(“#user-#{@id}”)

 signOut: ->
   ...
6th Cup: Context, the classy way
                Classes

class User
  constructor: (@id, @name) ->
    @element = $(“#user-#{@id}”)

 signOut: ->
   ...
6th Cup: Context, the classy way
                Classes

class User
  constructor: (@id, @name) ->
    @element = $(“#user-#{@id}”)

 signOut: ->
   ...
6th Cup: Context, the classy way
                Classes

class User
  constructor: (@id, @name) ->
    @element = $(“#user-#{@id}”)

 signOut: ->
   ...
6th Cup: Context, the classy way
               Inheritance

class User
  constructor: (@id, @name) ->
    @element = $(“#user-#{@id}”)

 signOut: ->
   ...
6th Cup: Context, the classy way
              Inheritance

class SignedInUser extends User
  ...

class SignedOutUser extends User
  ...
6th Cup: Context, the classy way
                super

class SignedInUser extends User
  constructor: (args...) ->
    super args...

   $(“a.sign-out”, @element).click =>
     this.signOut()
6th Cup: Context, the classy way
           On variable locality

class User
  constructor: (@id, @name) ->
    @element = $(“#user-#{@id}”)

 signOut: ->
   ...
6th Cup: Context, the classy way
           On variable locality

class window.User
  constructor: (@id, @name) ->
    @element = $(“#user-#{@id}”)

 signOut: ->
   ...
6th Cup: Context, the classy way
           On variable locality

class window.User
  constructor: (@id, @name) ->
    @element = $(“#user-#{@id}”)

 signOut: ->
   ...
6th Cup: Context, the classy way
           On variable locality

class this.User
  constructor: (@id, @name) ->
    @element = $(“#user-#{@id}”)

 signOut: ->
   ...
6th Cup: Context, the classy way
           On variable locality

class @User
  constructor: (@id, @name) ->
    @element = $(“#user-#{@id}”)

 signOut: ->
   ...
We’ve Covered
➡ Object Literals        ➡ Existential Operator
➡ String Interpolation   ➡ Context and this
➡ Functions              ➡ Property Accessors
➡ Default Arguments      ➡ Bound Functions
➡ Splats                 ➡ Classes
➡ Ranges                 ➡ Inheritance
➡ Pattern Matching       ➡ super
So…
…is it worth it?
Questions?
Thanks!
Thanks!

http://github.com/foca

      @godfoca
Thanks!

  http://github.com/foca

        @godfoca



jobs@cuboxsa.com
Follow-up:
Loop closures and do
Follow-up: Loop closures and do

for i in [1..5]
  console.log i
Follow-up: Loop closures and do

for i in [1..5]
  setTimeout (-> console.log i), 100
Follow-up: Loop closures and do

for i in [1..5]
  setTimeout (-> console.log i), 100

>   5
>   5
>   5
>   5
>   5
Follow-up: Loop closures and do

for i in [1..5]
  setTimeout (-> console.log i), 100

>   5
>   5
>   5
>   5
>   5
Follow-up: Loop closures and do

for i in [1..5]
  ((i) ->
    setTimeout (-> console.log i), 100
  )(i)

> 1
> 2
> ...
Follow-up: Loop closures and do

for i in [1..5]
  do (i) ->
    setTimeout (-> console.log i), 100

> 1
> 2
> ...
Follow-up:
Comprehension Madness
Follow-up: Comprehension Madness
           Keep It Simple, Stupid


A = [1, 2, 3, 4, 5]
B = [8, 7, 1, 2]

cartesian = ([x, y] for x in A for y in B)
Follow-up: Comprehension Madness
                   Keep It Simple, Stupid




(ret.push(val) unless val in ret) for val in orig when shouldAdd(val)
Let's Have a Cup of CoffeeScript

More Related Content

Viewers also liked

My Project Report Documentation with Abstract & Snapshots
My Project Report Documentation with Abstract & SnapshotsMy Project Report Documentation with Abstract & Snapshots
My Project Report Documentation with Abstract & SnapshotsUsman Sait
 
The Real World May 2016.pptx2
The Real World May 2016.pptx2The Real World May 2016.pptx2
The Real World May 2016.pptx2Posterscope
 
NodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time WebNodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time WebJakub Nesetril
 
Consuming API description languages - Refract & Minim
Consuming API description languages - Refract & MinimConsuming API description languages - Refract & Minim
Consuming API description languages - Refract & MinimJakub Nesetril
 
Avoiding API Waterfalls
Avoiding API WaterfallsAvoiding API Waterfalls
Avoiding API WaterfallsJakub Nesetril
 
Budoucnost Web Aplikaci
Budoucnost Web AplikaciBudoucnost Web Aplikaci
Budoucnost Web AplikaciJakub Nesetril
 
Introduction to GoodData BI PaaS
Introduction to GoodData BI PaaSIntroduction to GoodData BI PaaS
Introduction to GoodData BI PaaSJakub Nesetril
 
Advanced Regular Expressions Redux
Advanced Regular Expressions ReduxAdvanced Regular Expressions Redux
Advanced Regular Expressions ReduxJakub Nesetril
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsJakub Nesetril
 
GoodData: One Stop Shop for Analytics
GoodData: One Stop Shop for AnalyticsGoodData: One Stop Shop for Analytics
GoodData: One Stop Shop for AnalyticsJakub Nesetril
 
SOS! Lectura Obligatòria. Chahida Haddad
SOS! Lectura Obligatòria. Chahida HaddadSOS! Lectura Obligatòria. Chahida Haddad
SOS! Lectura Obligatòria. Chahida HaddadCOBDC
 

Viewers also liked (20)

My Project Report Documentation with Abstract & Snapshots
My Project Report Documentation with Abstract & SnapshotsMy Project Report Documentation with Abstract & Snapshots
My Project Report Documentation with Abstract & Snapshots
 
The Real World May 2016.pptx2
The Real World May 2016.pptx2The Real World May 2016.pptx2
The Real World May 2016.pptx2
 
Happy Onam !!
Happy Onam !!Happy Onam !!
Happy Onam !!
 
Post-REST Manifesto
Post-REST ManifestoPost-REST Manifesto
Post-REST Manifesto
 
NodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time WebNodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time Web
 
Consuming API description languages - Refract & Minim
Consuming API description languages - Refract & MinimConsuming API description languages - Refract & Minim
Consuming API description languages - Refract & Minim
 
Harmony in API Design
Harmony in API DesignHarmony in API Design
Harmony in API Design
 
Startup Accelerators
Startup AcceleratorsStartup Accelerators
Startup Accelerators
 
Avoiding API Waterfalls
Avoiding API WaterfallsAvoiding API Waterfalls
Avoiding API Waterfalls
 
Budoucnost Web Aplikaci
Budoucnost Web AplikaciBudoucnost Web Aplikaci
Budoucnost Web Aplikaci
 
Introduction to GoodData BI PaaS
Introduction to GoodData BI PaaSIntroduction to GoodData BI PaaS
Introduction to GoodData BI PaaS
 
Art of Building APIs
Art of Building APIsArt of Building APIs
Art of Building APIs
 
REST API tools
REST API toolsREST API tools
REST API tools
 
Advanced Regular Expressions Redux
Advanced Regular Expressions ReduxAdvanced Regular Expressions Redux
Advanced Regular Expressions Redux
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
GoodData: One Stop Shop for Analytics
GoodData: One Stop Shop for AnalyticsGoodData: One Stop Shop for Analytics
GoodData: One Stop Shop for Analytics
 
SOS! Lectura Obligatòria. Chahida Haddad
SOS! Lectura Obligatòria. Chahida HaddadSOS! Lectura Obligatòria. Chahida Haddad
SOS! Lectura Obligatòria. Chahida Haddad
 
Node at Apiary.io
Node at Apiary.ioNode at Apiary.io
Node at Apiary.io
 
API Design Workflows
API Design WorkflowsAPI Design Workflows
API Design Workflows
 
Apiary
ApiaryApiary
Apiary
 

Similar to Let's Have a Cup of CoffeeScript

(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and ProfitOlaf Alders
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosEdgar Suarez
 
Scalding - the not-so-basics @ ScalaDays 2014
Scalding - the not-so-basics @ ScalaDays 2014Scalding - the not-so-basics @ ScalaDays 2014
Scalding - the not-so-basics @ ScalaDays 2014Konrad Malawski
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?osfameron
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Wen-Tien Chang
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma IntroduçãoÍgor Bonadio
 
Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Paulo Morgado
 
Joshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayJoshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayRefresh Events
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Complex queries in a distributed multi-model database
Complex queries in a distributed multi-model databaseComplex queries in a distributed multi-model database
Complex queries in a distributed multi-model databaseMax Neunhöffer
 
ScotRuby - Dark side of ruby
ScotRuby - Dark side of rubyScotRuby - Dark side of ruby
ScotRuby - Dark side of rubyGautam Rege
 
Max Neunhöffer – Joins and aggregations in a distributed NoSQL DB - NoSQL mat...
Max Neunhöffer – Joins and aggregations in a distributed NoSQL DB - NoSQL mat...Max Neunhöffer – Joins and aggregations in a distributed NoSQL DB - NoSQL mat...
Max Neunhöffer – Joins and aggregations in a distributed NoSQL DB - NoSQL mat...NoSQLmatters
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionPaulo Morgado
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPaweł Dawczak
 

Similar to Let's Have a Cup of CoffeeScript (20)

An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit
 
JSON and the APInauts
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutos
 
Scalding - the not-so-basics @ ScalaDays 2014
Scalding - the not-so-basics @ ScalaDays 2014Scalding - the not-so-basics @ ScalaDays 2014
Scalding - the not-so-basics @ ScalaDays 2014
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma Introdução
 
Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#
 
Having Fun Programming!
Having Fun Programming!Having Fun Programming!
Having Fun Programming!
 
Joshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayJoshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages Today
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Complex queries in a distributed multi-model database
Complex queries in a distributed multi-model databaseComplex queries in a distributed multi-model database
Complex queries in a distributed multi-model database
 
Ruby
RubyRuby
Ruby
 
ScotRuby - Dark side of ruby
ScotRuby - Dark side of rubyScotRuby - Dark side of ruby
ScotRuby - Dark side of ruby
 
Max Neunhöffer – Joins and aggregations in a distributed NoSQL DB - NoSQL mat...
Max Neunhöffer – Joins and aggregations in a distributed NoSQL DB - NoSQL mat...Max Neunhöffer – Joins and aggregations in a distributed NoSQL DB - NoSQL mat...
Max Neunhöffer – Joins and aggregations in a distributed NoSQL DB - NoSQL mat...
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to Elixir
 

Recently uploaded

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 

Recently uploaded (20)

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 

Let's Have a Cup of CoffeeScript

  • 1. Let’s Have a Cup of
  • 2.
  • 4.
  • 5. me = { name: “Nicolás”, location: “Montevideo, Uruguay”, age: 26, likesWorkingOn: [“Ruby”, “JavaScript”], twitter: “@godfoca”, github: “http://github.com/foca”, url: “http://nicolassanguinetti.info”, company: { name: “Cubox”, url: “http://cuboxsa.com” } }
  • 6. me = { name: “Nicolás”, location: “Montevideo, Uruguay age: 26, likesWorkingOn: [“Ruby”, “Java twitter: “@godfoca”, github: “http://github.com/foc url: “http://nicolassanguinett company: { name: “Cubox”, url: “http://cuboxsa.com”
  • 7. me = { name: “Nicolás”, location: “Montevid age: 26, likesWorkingOn: [“R twitter: “@godfoca” github: “http://git
  • 8. me = { name: “Nicolás” location: “Mont age: 26, likesWorkingOn: twitter: “@godf
  • 9. There’s no var me = { name: “Nico location: age: 26,
  • 10.
  • 11. me = { name: “Nicolás”, location: “Montevideo, Uruguay”, age: 26, likesWorkingOn: [“Ruby”, “JavaScript”], twitter: “@godfoca”, github: “http://github.com/foca”, url: “http://nicolassanguinetti.info”, company: { name: “Cubox”, url: “http://cuboxsa.com” } }
  • 12.
  • 13. me = { name: “Nicolás”, location: “Montevideo, Uruguay”, age: 26, likesWorkingOn: [“Ruby”, “JavaScript”], twitter: “@godfoca”, github: “http://github.com/foca”, url: “http://nicolassanguinetti.info”, company: { name: “Cubox”, url: “http://cuboxsa.com” } }
  • 14. me = name: “Nicolás”, location: “Montevideo, Uruguay”, age: 26, likesWorkingOn: [“Ruby”, “JavaScript”], twitter: “@godfoca”, github: “http://github.com/foca”, url: “http://nicolassanguinetti.info”, company: name: “Cubox”, url: “http://cuboxsa.com”
  • 15. me = name: “Nicolás”, location: “Montevideo, Uruguay”, age: 26, likesWorkingOn: [“Ruby”, “JavaScript”], twitter: “@godfoca”, github: “http://github.com/foca”, url: “http://nicolassanguinetti.info”, company: name: “Cubox”, url: “http://cuboxsa.com”
  • 16. me = name: “Nicolás”, location: “Montevideo, Uruguay”, age: 26, likesWorkingOn: [“Ruby”, “JavaScript”], twitter: “@godfoca”, github: “http://github.com/foca”, url: “http://nicolassanguinetti.info”, company: name: “Cubox”, url: “http://cuboxsa.com”
  • 17. me = name: “Nicolás” location: “Montevideo, Uruguay” age: 26 likesWorkingOn: [“Ruby”, “JavaScript”] twitter: “@godfoca” github: “http://github.com/foca” url: “http://nicolassanguinetti.info” company: name: “Cubox” url: “http://cuboxsa.com”
  • 18. me = name: “Nicolás” location: “Montevideo, Uruguay” age: 26 likesWorkingOn: [“Ruby”, “JavaScript”] twitter: “@godfoca” github: “http://github.com/foca” url: “http://nicolassanguinetti.info” company: name: “Cubox” url: “http://cuboxsa.com”
  • 19. Let’s Have a few Cups of
  • 20. 1st Cup A simple comparison
  • 21. 1st Cup: A simple comparison var square = function(num) {   return num * num; } var list = [1, 2, 3, 4, 5]; var squares = []; for (var i = 0; i < list.length; i++) {   squares.push(square(list[i])); }
  • 22. 1st Cup: A simple comparison var square = function(num) {   return num * num; } var list = [1, 2, 3, 4, 5]; var squares = []; for (var i = 0; i < list.length; i++) {   squares.push(square(list[i])); }
  • 23. 1st Cup: A simple comparison var square = function(num) {   return num * num; } var list = [1, 2, 3, 4, 5]; var squares = []; for (var i = 0; i < list.length; i++) {   squares.push(square(list[i])); }
  • 24. 1st Cup: A simple comparison var square = function(num) {   return num * num; } var list = [1, 2, 3, 4, 5]; var squares = []; for (var i = 0; i < list.length; i++) {   squares.push(square(list[i])); }
  • 25. 1st Cup: A simple comparison var square = function(num) {   return num * num; } var list = [1, 2, 3, 4, 5]; var squares = []; for (var i = 0; i < list.length; i++) {   squares.push(square(list[i])); }
  • 26. 1st Cup: A simple comparison square = (num) -> num * num list = [1..5] squares = (square n for n in list)
  • 27. 1st Cup: A simple comparison square = (num) -> num * num list = [1..5] squares = (square n for n in list)
  • 28. 1st Cup: A simple comparison square = (num) -> num * num list = [1..5] squares = (square n for n in list)
  • 29. 1st Cup: A simple comparison square = (num) -> num * num list = [1..5] squares = (square n for n in list)
  • 30. 1st Cup: A simple comparison square = (num) -> num * num list = [1..5] squares = (square n for n in list)
  • 31. 2nd Cup The Useless Calculator
  • 32. 2nd Cup: The Useless Calculator var add = function(num1, num2) {   return num1 + “ + “ + num2 + “ = “ + (num1 + num2); } console.log(add(2, 3)) > 2 + 3 = 5 console.log(add(5, 7)) > 5 + 7 = 12
  • 33. 2nd Cup: The Useless Calculator var add = function(num1, num2) {   return num1 + “ + “ + num2 + “ = “ + (num1 + num2); } console.log(add(2, 3)) > 2 + 3 = 5 console.log(add(5, 7)) > 5 + 7 = 12
  • 34. 2nd Cup: The Useless Calculator var add = function(num1, num2) {   return num1 + “ + “ + num2 + “ = “ + (num1 + num2); } console.log(add(2, 3)) > 2 + 3 = 5 console.log(add(5, 7)) > 5 + 7 = 12
  • 35. 2nd Cup: The Useless Calculator var add = function(num1, num2) {   return num1 + “ + “ + num2 + “ = “ + (num1 + num2); } console.log(add(2, 3)) > 2 + 3 = 5 console.log(add(5, 7)) > 5 + 7 = 12
  • 36. 2nd Cup: The Useless Calculator var add = function(num1, num2) {   return num1 + “ + “ + num2 + “ = “ + (num1 + num2); } console.log(add(2, 3)) > 2 + 3 = 5 console.log(add(5, 7)) > 5 + 7 = 12
  • 37. 2nd Cup: The Useless Calculator add = (num1, num2) -> “#{num1} + #{num2} = #{num1 + num2}” console.log add(2, 3) > 2 + 3 = 5 console.log add(5, 7) > 5 + 7 = 12
  • 38. 2nd Cup: The Useless Calculator add = (num1, num2) -> “#{num1} + #{num2} = #{num1 + num2}” console.log add(2, 3) > 2 + 3 = 5 console.log add(5, 7) > 5 + 7 = 12
  • 39. 2nd Cup: The Useless Calculator add = (num1, num2) -> “#{num1} + #{num2} = #{num1 + num2}” console.log add(2, 3) > 2 + 3 = 5 console.log add(5, 7) > 5 + 7 = 12
  • 40. 2nd Cup: The Useless Calculator add = (num1, num2) -> “#{num1} + #{num2} = #{num1 + num2}” console.log add(2, 3) > 2 + 3 = 5 console.log add(5, 7) > 5 + 7 = 12
  • 41. 2nd Cup: The Useless Calculator add = (num1, num2) -> “#{num1} + #{num2} = #{num1 + num2}” console.log add(2, 3) > 2 + 3 = 5 console.log add(5, 7) > 5 + 7 = 12
  • 43. 3rd Cup: Your Favorite Language languageOfChoice = (lang) -> “#{lang} rocks!”
  • 44. 3rd Cup: Your Favorite Language languageOfChoice = (lang) -> “#{lang} rocks!” console.log languageOfChoice(“Ruby”) > Ruby rocks!
  • 45. 3rd Cup: Your Favorite Language Implicit Return languageOfChoice = (lang) -> “#{lang} rocks!”
  • 46. 3rd Cup: Your Favorite Language Implicit Return languageOfChoice = (lang) -> return “#{lang} rocks!”
  • 47. 3rd Cup: Your Favorite Language Implicit Return languageOfChoice = (lang) -> if lang == “PHP” “Get outta here!” else “#{lang} rocks!”
  • 48. 3rd Cup: Your Favorite Language Implicit Return languageOfChoice = (lang) -> if lang == “PHP” return “Get outta here!” else return “#{lang} rocks!”
  • 49. 3rd Cup: Your Favorite Language Default Arguments languageOfChoice = (lang = “Ruby”) -> “#{lang} rocks!”
  • 50. 3rd Cup: Your Favorite Language Default Arguments languageOfChoice = (lang = “Ruby”) -> “#{lang} rocks!” console.log languageOfChoice(“Lua”) > Lua rocks!
  • 51. 3rd Cup: Your Favorite Language Default Arguments languageOfChoice = (lang = “Ruby”) -> “#{lang} rocks!” console.log languageOfChoice(“Lua”) > Lua rocks! console.log languageOfChoice() > Ruby rocks!
  • 52. 3rd Cup: Your Favorite Language Optional Parentheses languageOfChoice = (lang = “Ruby”) -> “#{lang} rocks!”
  • 53. 3rd Cup: Your Favorite Language Optional Parentheses languageOfChoice = (lang = “Ruby”) -> “#{lang} rocks!” console.log languageOfChoice “Lua” > Lua rocks!
  • 54. 3rd Cup: Your Favorite Language Optional Parentheses languageOfChoice = (lang = “Ruby”) -> “#{lang} rocks!” console.log languageOfChoice “Lua” > Lua rocks! console.log languageOfChoice
  • 55. 3rd Cup: Your Favorite Language Optional Parentheses languageOfChoice = (lang = “Ruby”) -> “#{lang} rocks!” console.log languageOfChoice “Lua” > Lua rocks! console.log languageOfChoice > [function “languageOfChoice”]
  • 56. 3rd Cup: Your Favorite Language Optional Parentheses languageOfChoice = (lang = “Ruby”) -> “#{lang} rocks!” console.log languageOfChoice “Lua” > Lua rocks! console.log languageOfChoice > [function “languageOfChoice”] console.log languageOfChoice() > Ruby rocks!
  • 57. 3rd Cup: Your Favorite Language Splats languagesOfChoice = (langs...) -> “I like #{langs.join(“, “)}”
  • 58. 3rd Cup: Your Favorite Language Splats languagesOfChoice = (langs...) -> “I like #{langs.join(“, “)}” languagesOfChoice “Ruby”, “JS”, “Python” > I like Ruby, JS, Python
  • 59. 3rd Cup: Your Favorite Language Splats myLangs = [“Ruby”, “JS”, “Python”]
  • 60. 3rd Cup: Your Favorite Language Splats myLangs = [“Ruby”, “JS”, “Python”] languagesOfChoice myLangs... > I like Ruby, JS, Python
  • 61. 3rd Cup: Your Favorite Language Splats languagesOfChoice = (best, langs...) -> “I love #{best}, and I like #{langs.join(“, “)}”
  • 62. 3rd Cup: Your Favorite Language Splats languagesOfChoice = (best, langs...) -> “I love #{best}, and I like #{langs.join(“, “)}” languagesOfChoice “Ruby”, “JS”, “Python” > I love Ruby, and I like JS, Python
  • 63. 3rd Cup: Your Favorite Language Splats languagesOfChoice = (langs..., worst) -> “I like #{langs.join(“, “)}, but I hate #{worst}”
  • 64. 3rd Cup: Your Favorite Language Splats languagesOfChoice = (langs..., worst) -> “I like #{langs.join(“, “)}, but I hate #{worst}” languagesOfChoice “Ruby”, “JS”, “PHP” > I like Ruby, JS, but I hate PHP
  • 65. 3rd Cup: Your Favorite Language Existential Operator languagesOfChoice = (best, langs...) -> “I love #{best}, and I like #{langs.join(“, “)}”
  • 66. 3rd Cup: Your Favorite Language Existential Operator languagesOfChoice = (best, langs...) -> “I love #{best}, and I like #{langs.join(“, “)}” languagesOfChoice “Ruby” > I love Ruby, and I like
  • 67. 3rd Cup: Your Favorite Language Existential Operator languagesOfChoice = (best, langs...) -> “I love #{best}, and I like #{langs.join(“, “)}” languagesOfChoice “Ruby” > I love Ruby, and I like languagesOfChoice() > I love , and I like
  • 68. 3rd Cup: Your Favorite Language Existential Operator languagesOfChoice = (best, langs...) -> ret = [] if best? ret.push “I love #{best}” if langs.length > 0 ret.push “I like #{langs.join(“, “)}” ret.join(“, and “)
  • 69. 3rd Cup: Your Favorite Language Existential Operator languagesOfChoice = (best, langs...) -> ret = [] if best? ret.push “I love #{best}” if langs.length > 0 ret.push “I like #{langs.join(“, “)}” ret.join(“, and “)
  • 70. 3rd Cup: Your Favorite Language Existential Operator languagesOfChoice = (best, langs...) -> ret = [] if best? ret.push “I love #{best}” if langs.length > 0 ret.push “I like #{langs.join(“, “)}” ret.join(“, and “)
  • 71. 3rd Cup: Your Favorite Language Existential Operator languagesOfChoice = (best, langs...) -> ret = [] if best? ret.push “I love #{best}” if langs.length > 0 ret.push “I like #{langs.join(“, “)}” ret.join(“, and “)
  • 72. 3rd Cup: Your Favorite Language Existential Operator languagesOfChoice = (best, langs...) -> ret = [] if best? ret.push “I love #{best}” if langs.length > 0 ret.push “I like #{langs.join(“, “)}” ret.join(“, and “)
  • 73. 3rd Cup: Your Favorite Language Existential Operator languagesOfChoice “Ruby”, “JS”, “Python” > I love Ruby, and I like JS, Python
  • 74. 3rd Cup: Your Favorite Language Existential Operator languagesOfChoice “Ruby”, “JS”, “Python” > I love Ruby, and I like JS, Python languagesOfChoice “Ruby” > I love Ruby
  • 75. 3rd Cup: Your Favorite Language Existential Operator languagesOfChoice “Ruby”, “JS”, “Python” > I love Ruby, and I like JS, Python languagesOfChoice “Ruby” > I love Ruby languagesOfChoice undefined, “Ruby”, “JS” > I like Ruby, JS
  • 76. 3rd Cup: Your Favorite Language Existential Operator languagesOfChoice “Ruby”, “JS”, “Python” > I love Ruby, and I like JS, Python languagesOfChoice “Ruby” > I love Ruby languagesOfChoice undefined, “Ruby”, “JS” > I like Ruby, JS languagesOfChoice() > “”
  • 77. 3rd Cup: Your Favorite Language Existential Operator expr?
  • 78. 3rd Cup: Your Favorite Language Existential Operator expr? typeof expr !== undefined && expr !== null
  • 79. 3rd Cup: Your Favorite Language Existential Operator x ?= y
  • 80. 3rd Cup: Your Favorite Language Existential Operator x ?= y x = y unless x?
  • 81. 3rd Cup: Your Favorite Language Existential Operator obj = x: { y: 2 }
  • 82. 3rd Cup: Your Favorite Language Existential Operator obj = x: { y: 2 } obj.x?.y
  • 83. 3rd Cup: Your Favorite Language Existential Operator obj = x: { y: 2 } obj.x?.y if obj.x? then obj.x.y else undefined
  • 84. 3rd Cup: Your Favorite Language Existential Operator obj = x: { y: 2 } obj.x?.y if obj.x? then obj.x.y else undefined
  • 85. 3rd Cup: Your Favorite Language Existential Operator obj = x: { y: 2 } obj.x?.y if obj.x? then obj.x.y else undefined
  • 86. 3rd Cup: Your Favorite Language Existential Operator obj = x: { y: 2 } obj.x?.y if obj.x? then obj.x.y else undefined
  • 87. 3rd Cup: Your Favorite Language Existential Operator func?()
  • 88. 3rd Cup: Your Favorite Language Existential Operator func?() func() if typeof func == “function”
  • 89. 3rd Cup: Your Favorite Language Existential Operator options.callback?()
  • 91. Interlude: Ranges [1..5] #=> [1, 2, 3, 4, 5]
  • 92. Interlude: Ranges [1..5] #=> [1, 2, 3, 4, 5] [1...5] #=> [1, 2, 3, 4]
  • 93. Interlude: Ranges list = [1, 2, 3, 4, 5] list[2..3] #=> [3, 4]
  • 94. Interlude: Ranges list = [1, 2, 3, 4, 5] list[2..-1] #=> [3, 4, 5]
  • 96. 4th Cup: Patterns list = [“Ruby”, “JS”, “Python”]
  • 97. 4th Cup: Patterns list = [“Ruby”, “JS”, “Python”] Head Tail
  • 98. 4th Cup: Patterns list = [“Ruby”, “JS”, “Python”] head = list[0] tail = list[1..-1]
  • 99. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [head, tail] = [list[0], list[1..-1]]
  • 100. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [head, tail] = [list[0], list[1..-1]] Pattern
  • 101. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [head, tail] = [list[0], list[1..-1]] Pattern Values
  • 102. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [head, tail] = [list[0], list[1..-1]]
  • 103. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [head, tail] = [list[0], list[1..-1]]
  • 104. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [head, tail] = [list[0], list[1..-1]] head #=> “Ruby”
  • 105. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [head, tail] = [list[0], list[1..-1]] head #=> “Ruby” tail #=> [“JS”, “Python”]
  • 106. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [head, tail...] = list
  • 107. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [head, tail...] = list
  • 108. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [head, tail...] = list head #=> “Ruby”
  • 109. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [head, tail...] = list head #=> “Ruby” tail #=> [“JS”, “Python”]
  • 110. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [top, rest..., bottom] = list
  • 111. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [top, rest..., bottom] = list top #=> “Ruby”
  • 112. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [top, rest..., bottom] = list top #=> “Ruby” bottom #=> “Python”
  • 113. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”, “Python”] [top, rest..., bottom] = list top #=> “Ruby” bottom #=> “Python” rest #=> [“JS”]
  • 114. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”] [top, rest..., bottom] = list
  • 115. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”] [top, rest..., bottom] = list top #=> “Ruby”
  • 116. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”] [top, rest..., bottom] = list top #=> “Ruby” bottom #=> “JS”
  • 117. 4th Cup: Patterns Pattern Matching list = [“Ruby”, “JS”] [top, rest..., bottom] = list top #=> “Ruby” bottom #=> “JS” rest #=> []
  • 118. 4th Cup: Patterns Pattern Matching me = name: “Nicolás” age: 26 company: name: “Cubox”
  • 119. 4th Cup: Patterns Pattern Matching me = name: “Nicolás” age: 26 company: name: “Cubox” name = me.name age = me.age
  • 120. 4th Cup: Patterns Pattern Matching me = name: “Nicolás” age: 26 company: name: “Cubox” { name: name, age: age } = me
  • 121. 4th Cup: Patterns Pattern Matching me = name: “Nicolás” age: 26 company: name: “Cubox” { name: name, age: age } = me Pattern
  • 122. 4th Cup: Patterns Pattern Matching me = name: “Nicolás” age: 26 company: name: “Cubox” { name: name, age: age } = me Variables
  • 123. 4th Cup: Patterns Pattern Matching me = name: “Nicolás” age: 26 company: name: “Cubox” { name: name, age: age } = me Values
  • 124. 4th Cup: Patterns Pattern Matching me = name: “Nicolás” age: 26 company: name: “Cubox” { name: name, age: age } = me name #=> “Nicolás” age #=> 26
  • 125. 4th Cup: Patterns Pattern Matching { name, age } = me
  • 126. 4th Cup: Patterns Pattern Matching { name, age } = me name #=> “Nicolás”
  • 127. 4th Cup: Patterns Pattern Matching { name, age } = me name #=> “Nicolás” age #=> 26
  • 129. 5th Cup: Collecting Collections Iterating over arrays list = [1..10] for item in list doSomethingWith(item)
  • 130. 5th Cup: Collecting Collections Iterating over arrays list = [1..10] for item in list doSomethingWith(item)
  • 131. 5th Cup: Collecting Collections Iterating over objects me = name: “Nicolás”, age: 26 for key, value of me console.log “#{key}: #{value}”
  • 132. 5th Cup: Collecting Collections Iterating over objects me = name: “Nicolás”, age: 26 for key, value of me console.log “#{key}: #{value}”
  • 133. 5th Cup: Collecting Collections Comprehensions alert n for n in [1..5]
  • 134. 5th Cup: Collecting Collections Comprehensions alert n for n in [1..5]
  • 135. 5th Cup: Collecting Collections Comprehensions doubles = (n * 2 for n in [1..5])
  • 136. 5th Cup: Collecting Collections Filtering Comprehensions alert n for n in [1..5] when n > 2
  • 137. 5th Cup: Collecting Collections Filtering Comprehensions alert n for n in [1..5] when n > 2
  • 138. 5th Cup: Collecting Collections Filtering Comprehensions alert n for n in [1..5] when n > 2 for n in [1..5] continue unless n > 2 alert n
  • 139. 5th Cup: Collecting Collections Filtering Comprehensions alert n for n in [1..5] when n > 2 for n in [1..5] continue unless n > 2 alert n
  • 140. Interlude this
  • 141. Interlude: this function isCute() { return this.cute; }
  • 142. Interlude: this var cuteKitty = { cute: true, isCute: isCute };
  • 143. Interlude: this var meanKitty = { cute: false, isCute: isCute };
  • 144. Interlude: this cuteKitty.isCute() meanKitty.isCute()
  • 145. Interlude: this cuteKitty.isCute() meanKitty.isCute() true
  • 146. Interlude: this cuteKitty.isCute() meanKitty.isCute() true false
  • 147. Interlude: this function whatHappensNow() { console.log(this); } whatHappensNow()
  • 148. Interlude: this function whatHappensNow() { console.log(this); } whatHappensNow() > [window]
  • 151. Interlude: this $(“a.sign-out”).click(function() { console.log(this); }); <a href=”#” class=”delete”>Delete</a>
  • 153. Interlude: this function returnThis() { return this; } returnThis.apply(42); //=> 42
  • 154. Interlude: this function returnThis() { return this; } returnThis.apply(42); //=> 42 returnThis.apply(“hi”); //=> “hi”
  • 155. 6th Cup Context, the classy way
  • 156. 6th Cup: Context, the classy way User = (id, name) -> this.id = id this.name = name this.element = $(“#user-#{this.id}”)
  • 157. 6th Cup: Context, the classy way Context Accessor User = (id, name) -> this.id = id this.name = name this.element = $(“#user-#{this.id}”)
  • 158. 6th Cup: Context, the classy way Context Accessor User = (id, name) -> this.id = id this.name = name this.element = $(“#user-#{this.id}”)
  • 159. 6th Cup: Context, the classy way Context Accessor User = (id, name) -> this.id = id this.name = name this.element = $(“#user-#{this.id}”)
  • 160. 6th Cup: Context, the classy way Context Accessor User = (id, name) -> this.id = id this.name = name this.element = $(“#user-#{this.id}”)
  • 161. 6th Cup: Context, the classy way Context Accessor User = (id, name) -> @id = id @name = name @element = $(“#user-#{@id}”)
  • 162. 6th Cup: Context, the classy way Property Arguments User = (id, name) -> @id = id @name = name @element = $(“#user-#{@id}”)
  • 163. 6th Cup: Context, the classy way Property Arguments User = (id, name) -> @id = id @name = name @element = $(“#user-#{@id}”)
  • 164. 6th Cup: Context, the classy way Property Arguments User = (@id, @name) -> @element = $(“#user-#{@id}”)
  • 165. 6th Cup: Context, the classy way Property Arguments User = (@id, @name) -> @element = $(“#user-#{@id}”)
  • 166. 6th Cup: Context, the classy way Property Arguments User = (@id, @name) -> @element = $(“#user-#{@id}”)
  • 167. 6th Cup: Context, the classy way User = (@id, @name) -> @element = $(“#user-#{@id}”)
  • 168. 6th Cup: Context, the classy way Bound Functions User = (@id, @name) -> @element = $(“#user-#{@id}”) User.prototype.signOut = -> $.ajax(...)
  • 169. 6th Cup: Context, the classy way Bound Functions User = (@id, @name) -> @element = $(“#user-#{@id}”) User.prototype.signOut = -> $.ajax(...)
  • 170. 6th Cup: Context, the classy way Bound Functions User = (@id, @name) -> @element = $(“#user-#{@id}”) User.prototype.signOut = -> $.ajax(...)
  • 171. 6th Cup: Context, the classy way Bound Functions User = (@id, @name) -> @element = $(“#user-#{@id}”) $(“a.sign-out”, @element).click -> this.signOut() false User.prototype.signOut = -> $.ajax(...)
  • 172. 6th Cup: Context, the classy way Bound Functions User = (@id, @name) -> @element = $(“#user-#{@id}”) $(“a.sign-out”, @element).click -> this.signOut() false User.prototype.signOut = -> $.ajax(...)
  • 173. 6th Cup: Context, the classy way Bound Functions User = (@id, @name) -> @element = $(“#user-#{@id}”) $(“a.sign-out”, @element).click -> this.signOut() false User.prototype.signOut = -> $.ajax(...)
  • 174.
  • 175. 6th Cup: Context, the classy way Bound Functions User = (@id, @name) -> @element = $(“#user-#{@id}”) self = this $(“a.sign-out”, @element).click -> self.signOut() false User.prototype.signOut = -> $.ajax(...)
  • 176. 6th Cup: Context, the classy way Bound Functions User = (@id, @name) -> @element = $(“#user-#{@id}”) self = this $(“a.sign-out”, @element).click -> self.signOut() false User.prototype.signOut = -> $.ajax(...)
  • 177. 6th Cup: Context, the classy way Bound Functions User = (@id, @name) -> @element = $(“#user-#{@id}”) $(“a.sign-out”, @element).click => this.signOut() false User.prototype.signOut = -> $.ajax(...)
  • 178. 6th Cup: Context, the classy way Bound Functions User = (@id, @name) -> @element = $(“#user-#{@id}”) $(“a.sign-out”, @element).click => this.signOut() false User.prototype.signOut = -> $.ajax(...)
  • 179. 6th Cup: Context, the classy way Bound Functions User = (@id, @name) -> @element = $(“#user-#{@id}”) $(“a.sign-out”, @element).click => this.signOut() false User.prototype.signOut = -> $.ajax(...)
  • 180. 6th Cup: Context, the classy way User = (@id, @name) -> @element = $(“#user-#{@id}”) User.prototype.signOut = -> ...
  • 181. 6th Cup: Context, the classy way Classes class User constructor: (@id, @name) -> @element = $(“#user-#{@id}”) signOut: -> ...
  • 182. 6th Cup: Context, the classy way Classes class User constructor: (@id, @name) -> @element = $(“#user-#{@id}”) signOut: -> ...
  • 183. 6th Cup: Context, the classy way Classes class User constructor: (@id, @name) -> @element = $(“#user-#{@id}”) signOut: -> ...
  • 184. 6th Cup: Context, the classy way Classes class User constructor: (@id, @name) -> @element = $(“#user-#{@id}”) signOut: -> ...
  • 185. 6th Cup: Context, the classy way Inheritance class User constructor: (@id, @name) -> @element = $(“#user-#{@id}”) signOut: -> ...
  • 186. 6th Cup: Context, the classy way Inheritance class SignedInUser extends User ... class SignedOutUser extends User ...
  • 187. 6th Cup: Context, the classy way super class SignedInUser extends User constructor: (args...) -> super args... $(“a.sign-out”, @element).click => this.signOut()
  • 188. 6th Cup: Context, the classy way On variable locality class User constructor: (@id, @name) -> @element = $(“#user-#{@id}”) signOut: -> ...
  • 189. 6th Cup: Context, the classy way On variable locality class window.User constructor: (@id, @name) -> @element = $(“#user-#{@id}”) signOut: -> ...
  • 190. 6th Cup: Context, the classy way On variable locality class window.User constructor: (@id, @name) -> @element = $(“#user-#{@id}”) signOut: -> ...
  • 191. 6th Cup: Context, the classy way On variable locality class this.User constructor: (@id, @name) -> @element = $(“#user-#{@id}”) signOut: -> ...
  • 192. 6th Cup: Context, the classy way On variable locality class @User constructor: (@id, @name) -> @element = $(“#user-#{@id}”) signOut: -> ...
  • 193.
  • 194. We’ve Covered ➡ Object Literals ➡ Existential Operator ➡ String Interpolation ➡ Context and this ➡ Functions ➡ Property Accessors ➡ Default Arguments ➡ Bound Functions ➡ Splats ➡ Classes ➡ Ranges ➡ Inheritance ➡ Pattern Matching ➡ super
  • 195. So…
  • 197.
  • 198.
  • 202. Thanks! http://github.com/foca @godfoca jobs@cuboxsa.com
  • 203.
  • 205. Follow-up: Loop closures and do for i in [1..5] console.log i
  • 206. Follow-up: Loop closures and do for i in [1..5] setTimeout (-> console.log i), 100
  • 207. Follow-up: Loop closures and do for i in [1..5] setTimeout (-> console.log i), 100 > 5 > 5 > 5 > 5 > 5
  • 208.
  • 209. Follow-up: Loop closures and do for i in [1..5] setTimeout (-> console.log i), 100 > 5 > 5 > 5 > 5 > 5
  • 210. Follow-up: Loop closures and do for i in [1..5] ((i) -> setTimeout (-> console.log i), 100 )(i) > 1 > 2 > ...
  • 211. Follow-up: Loop closures and do for i in [1..5] do (i) -> setTimeout (-> console.log i), 100 > 1 > 2 > ...
  • 213. Follow-up: Comprehension Madness Keep It Simple, Stupid A = [1, 2, 3, 4, 5] B = [8, 7, 1, 2] cartesian = ([x, y] for x in A for y in B)
  • 214. Follow-up: Comprehension Madness Keep It Simple, Stupid (ret.push(val) unless val in ret) for val in orig when shouldAdd(val)

Editor's Notes

  1. \n
  2. Here to talk CoffeeScript \nCS is lang generates JS\n***\nBut first: JavaScript\n
  3. Quick Hack: 10 days\nLisp and self, political: C syntax\nBut, web&amp;#x2019;s lingua franca\nSome Good Parts\nSome Not-So-Good Parts\n
  4. Not-So-Good outweigh Good\nCoffee focuses on Good\nHides bad.\n***\nbut first, this is me\n
  5. but first, this is me\nname / location / work\nhere&amp;#x2019;s some javascript\nthere&amp;#x2019;s something very wrong with it\n
  6. \n
  7. \n
  8. \n
  9. there&amp;#x2019;s no var\nme is global\npotentially dangerous\nand a very common mistake\ndon&amp;#x2019;t want to debug sth for 3 hours\nfind out it was you who made the mistake\nvery frustrating\n
  10. fortunately here to talk about cs\ncs has no var keyword :)\n
  11. perfectly valid cs\n*whew*\nin cs all vars are local\nwant global? force it\n***\nhaml\n
  12. cs and haml compared a lot\nboth abstractions\nboth generate known language\n&amp;#x2026;both have significant whitespace\n\n
  13. fns must be indented if span mult lines\nifs and other statements as well\nbut cs also takes advantage w/ obj lit\n***\nignore curlies\n
  14. by making curly braces optional\n
  15. if you indent your keys properly\n
  16. it goes beyond curly braces\nif we write one key:value per line\n
  17. commas are also optional\n
  18. so this is me, in coffeescript\n
  19. just one cup? unacceptable\nstructured in various examples\n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. VERY succinct\ndare I say more expressive\n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. let&amp;#x2019;s talk functions\nsimple syntax\nargs, arrow, body\n
  44. call as any other fn\n***\nimplicit return\n
  45. no need to return from functions\n
  46. last statement always has implicit return\n***\nif/etc constructs\n
  47. even if last statement is an if, while, etc\n
  48. it always has an implicit return\n***\ndefault args, favorite lang?\n
  49. fns can take def args\n\n
  50. \n
  51. ***\noptional parens\n
  52. you prob noticed I call fns w/o ()\n
  53. this is perfectly valid\n
  54. what do you expect will happen?\n
  55. fns are 1st class objects\nreferring to a fn will return the fn obj\n
  56. if the fn takes no arguments\nparens are mandatory\n***\nhaving to choose one lang is unfair\nI like ruby, js, python, lua, coffee&amp;#x2026;\nlet&amp;#x2019;s make our function accept mult args\nalready in js: arguments, but clunky\n
  57. by using ... we tell the function\ntake all args, pass array w/ them to the fn\n
  58. by using ... we tell the function\ntake all args, pass array w/ them to the fn\n***\nsplat when calling\n
  59. let&amp;#x2019;s say we have an array\n
  60. can use splats to expand it to args\n\nbut even if we like a lot of langs\nwe always have a favorite\n
  61. splats can be after arguments\n
  62. ***\nbut splats don&amp;#x2019;t need to go at the end\n
  63. as long as you have only one splat\nthey can go anywhere\n
  64. \n
  65. go back to thinking positive\nwhat happens when called with 1 arg?\n
  66. or no args?\n
  67. so let&amp;#x2019;s fix that\nwe need to return both separately\ncheck &amp;#x2018;best&amp;#x2019; -&gt; return I love...\ncheck &amp;#x2018;langs&amp;#x2019; -&gt; return I like...\ndefine array, add each bit iff, join array\n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. let&amp;#x2019;s try it\n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. ***\nranges\n
  90. \n
  91. very much like ruby\nexcept only for numbers\nwe have inclusive ranges\n
  92. and exclusive ranges\n***\nnot only for generating arrays\n
  93. ranges are useful for slicing\n
  94. and they support negative ind\n
  95. \n
  96. \n
  97. \n
  98. \n
  99. assign mult vars at the same time\n
  100. assign mult vars at the same time\n
  101. assign mult vars at the same time\n
  102. 1st is matched to the 1st element\n
  103. 2nd element is matched to 2nd\n
  104. this works\nwe get what we want\n
  105. but syntax is very noisy\nin fact, it was better before!\n
  106. we match a list to a list\n
  107. \n
  108. \n
  109. \n
  110. assign mult vars at the same time\n
  111. assign mult vars at the same time\n
  112. assign mult vars at the same time\n
  113. assign mult vars at the same time\n
  114. what would happen now?\n
  115. what would happen now?\n
  116. what would happen now?\n
  117. non-splat args always take precedence over splats\n***\nranges&amp;#x2026;pat match is not only meant for arrays\n
  118. we&amp;#x2019;ve an obj literal\nwe want to get the name and age\n
  119. simple, right?\nbut we want pattern matching\n
  120. \n
  121. \n
  122. \n
  123. \n
  124. but still, there&amp;#x2019;s repetition\nvar == key\n
  125. \n
  126. \n
  127. ***\ncollections\n
  128. - iterations\n- array comprehensions\n\n
  129. basic iteration on an array\n
  130. you use in for arrays\n
  131. can also iterate over key/val on objects\n
  132. watch out! of for gral objects\n
  133. comprehensions\niterate over a list and do sth with items\n
  134. just a postfix for (almost)\n
  135. also, map\n
  136. or select/filter\n\n
  137. when is equivalent to skipping items\nreturned array only has subset\n***\nif you expanded this into a full for\n
  138. when is equivalent to skipping steps\n
  139. ***\nthis\n
  140. &lt;show hands&gt; how many fully understand this?\njavascript has keyword &amp;#x201C;this&amp;#x201D;\nit refers to current &amp;#x201C;evaluation context&amp;#x201D;\nakin to current scope\n
  141. we have a cat\n
  142. \n
  143. \n
  144. \n
  145. \n
  146. this is the receiver when explicit receiver\n
  147. can anyone tell?\n
  148. no receiver: this is top context\n
  149. \n
  150. \n
  151. \n
  152. how does jquery do it?\n
  153. fn.apply\n
  154. &amp;#x201C;this&amp;#x201D; refers to whatever we pass\n***\nfinal cup: context\n
  155. \n
  156. \n
  157. \n
  158. \n
  159. \n
  160. ***\ncs takes @ from ruby\n
  161. there&amp;#x2019;s a bit of repetition\n***\nproperty arguments\n
  162. define arguments&amp;#x2026;\n\n
  163. &amp;#x2026; just to assign them to this.whatever\n
  164. shorthand syntax\n
  165. assigns the first argument to this.id\n
  166. assigns the second argument to this.name\n
  167. \n
  168. let&amp;#x2019;s say user has signout fn\n\n
  169. triggers ajax request\nwe don&amp;#x2019;t care about internals\n
  170. trigger by a browser event\n
  171. naive implementation\n
  172. naive implementation\ndoesn&amp;#x2019;t work\n
  173. dom element\n
  174. \n
  175. naive solution\n
  176. naive solution\n
  177. better solution\n
  178. better solution\nforces this inside function\nwraps function so it calls apply\n
  179. ***\nlet&amp;#x2019;s disregard the impl\n
  180. pretty, but not idiomatic\nthis looks a lot like a class\n
  181. \n
  182. class keyword\n
  183. constructor function\n
  184. other functions are just nested\nno explicit prototypes\n
  185. user abilities depend on user signed in or not\neg only signed in users can signOut\n
  186. user abilities depend on user signed in or not\nwe can extend User to provide specifics\n
  187. and we can use super\n
  188. CS wraps everything on an ANON FREE fn\nso everything is truly local to the file it&amp;#x2019;s defined on\nnice, but we want classes outside!\n\n\n
  189. global class\n\n
  190. anon free fn =&gt; this is window\n\n
  191. anon free fn =&gt; this is window\n\n
  192. you can use @\n\n
  193. \n
  194. \n
  195. \n
  196. you tell me :)\n\n
  197. there&amp;#x2019;s a large community\n
  198. big names using it like 37s\n
  199. \n
  200. \n
  201. \n
  202. \n
  203. \n
  204. \n
  205. let&amp;#x2019;s take this simple for loop\n
  206. suppose we need timeouts\nwe wrap it in a function\nbut&amp;#x2026;\n
  207. \n
  208. \n
  209. js passes last value to closure\n
  210. solution: autocalling fn\nensure closure gets proper val\n
  211. cs has a shorthand :)\n
  212. \n
  213. this can start getting weird\n\n
  214. and get downright out of hand\n
  215. down this road lies madness\nKeep It Simple, Stupid\n