Last active
November 23, 2016 12:52
-
-
Save szymonskirgajllo/dc3af4ac743ee04de56fa54056811838 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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