Skip to content

Instantly share code, notes, and snippets.

@tmikeschu

tmikeschu/es6.md Secret

Forked from case-eee/es6.md
Created May 9, 2017 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tmikeschu/7346d97214d6b47d1a52f9ff8d1d698d to your computer and use it in GitHub Desktop.
Save tmikeschu/7346d97214d6b47d1a52f9ff8d1d698d to your computer and use it in GitHub Desktop.
es6

String Interpolation

const customer = { name: "Foo" }
const card = { amount: 7, product: "Bar", unitprice: 42 }
const message = `Hello ${customer.name},
want to buy ${card.amount} ${card.product} for
a total of ${card.amount * card.unitprice} bucks?`

Arrow Syntax

const odds = evens.map(v => 
  v + 1
)

const pairs = evens.map(v => 
  ({ even: v, odd: v + 1 })
)

const nums = evens.map((v, i) => 
  v + i
)

Arrow Syntax & This

$('.btn').click((event) =>{
  this.sendData()
})

Default Parameters

const addNumbers = (x, y = 7, z = 42) {
    return x + y + z
}

addNumbers(1) === 50

Classes & Prototypes

class Shape {
    constructor (id, x, y) {
        this.id = id
        this.move(x, y)
    }

    move (x, y) {
        this.x = x
        this.y = y
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment