Skip to content

Instantly share code, notes, and snippets.

@szymonskirgajllo
Last active November 23, 2016 12:52
Show Gist options
  • Select an option

  • Save szymonskirgajllo/dc3af4ac743ee04de56fa54056811838 to your computer and use it in GitHub Desktop.

Select an option

Save szymonskirgajllo/dc3af4ac743ee04de56fa54056811838 to your computer and use it in GitHub Desktop.
ES5:
function multiply(a, b) {
var b = typeof b !== 'undefined' ? b : 1;
return a * b;
}
ES6:
function multiply(a, b = 1) {
return a*b;
}
============================
ES5:
var self = this
$('.btn').click(function(event){
self.sendData()
})
ES6:
$('.btn').click((event) =>{
this.sendData()
})
===============================
// example with class
ES5 way
class Clicker {
doClick() {
setTimeout(function() {
console.log('end');
this.sendData(); // this.sendData is not a function...
}, 1000);
}
sendData() {
console.log('send');
}
}
var clicker = new Clicker();
clicker.doClick();
ES6 way:
class Clicker {
doClick() {
setTimeout(() => {
console.log('end');
this.sendData();}, 1000);
}
sendData() {
console.log('send');
}
}
var clicker = new Clicker();
clicker.doClick();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment