Skip to content

Instantly share code, notes, and snippets.

@case-eee

case-eee/es6.md Secret

Created March 28, 2017 16:20
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 case-eee/c21d882ce240215c8c7496a0d4408c7c to your computer and use it in GitHub Desktop.
Save case-eee/c21d882ce240215c8c7496a0d4408c7c to your computer and use it in GitHub Desktop.
es6

String Interpolation

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

Arrow Syntax

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

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

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

Arrow Syntax & This

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

Default Parameters

function 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