Created
February 3, 2016 23:21
-
-
Save kevinrogerteng/7b41af56ae97bc338aa6 to your computer and use it in GitHub Desktop.
This file contains 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 */ | |
var standardFunction = function () { | |
/* do stuff */ | |
} | |
function otherStandardFunction () { | |
} | |
var objectThing = { | |
methodName: function () {} | |
} | |
/* access self in a function */ | |
/* self binding stuff */ | |
var objectThing = { | |
someProperty: 'stuff', | |
methodName: function () { | |
var self = this; | |
var someStupidFunction = function () { | |
return self.someProperty; | |
}; | |
return someStupidFunction(); | |
} | |
} | |
/* ES6+ */ | |
/* all of the above + */ | |
/* ARROW FUNCTIONS */ | |
/* referentially transparent */ | |
let arrowFunction = (argument) => { | |
} | |
let arrowFunction = argument => { | |
} | |
/* no more self binding stuff */ | |
var objectThing = { | |
someProperty: 'stuff', | |
methodName: function () { | |
var someStupidFunction = () => { | |
return this.someProperty; | |
}; | |
return someStupidFunction(); | |
} | |
} | |
/* parenthesis(sp?) notation | |
/* implicitly returns the return value of someFunction */ | |
/* note: you can't do more than one operation */ | |
let arrowFunction = argument => ( | |
someFunction() | |
) | |
let arrowFunction = argument => someFunction() | |
/* object literals */ | |
es6ObjectLiteral = { | |
es5Function: function () { console.log(es6ObjectLiteral === this) }, | |
es6Function() { console.log(es6ObjectLiteral === this) } | |
arrowFunction: () => { console.log(es6ObjectLiteral === this) } | |
} | |
es6ObjectLiteral.es5Function() // true | |
es6ObjectLiteral.es6Function() // true | |
es6ObjectLiteral.arrowFunction() // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment