Skip to content

Instantly share code, notes, and snippets.

@kevinrogerteng
Created February 3, 2016 23:21
Show Gist options
  • Save kevinrogerteng/7b41af56ae97bc338aa6 to your computer and use it in GitHub Desktop.
Save kevinrogerteng/7b41af56ae97bc338aa6 to your computer and use it in GitHub Desktop.
/* 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