Skip to content

Instantly share code, notes, and snippets.

View jaspervalero's full-sized avatar

Jasper Valero jaspervalero

View GitHub Profile
@jaspervalero
jaspervalero / gist:bf14fdd48bf9eb07880d
Created March 11, 2015 02:21
Define the body of the function
var func = ( x, y ) => x + y;
@jaspervalero
jaspervalero / gist:c8b4e2977eb792b257bb
Created March 11, 2015 02:19
Add in that fat arrow goodness
var func = ( x, y ) =>
@jaspervalero
jaspervalero / gist:1336c685270bcb6c8d25
Created March 11, 2015 02:17
Provide the parameters
var func = ( x, y )
@jaspervalero
jaspervalero / gist:35c25edd74e65237f4f3
Created March 6, 2015 03:18
ES6 Arrow Function - Lambda-ish Implicit Return Example
var square = number => number * number;
console.log( square( 5 ) ); // 25
@jaspervalero
jaspervalero / gist:20dda9ee6fc36489d80f
Last active August 29, 2015 14:16
ES6 Lexical this Example
function Gamer() {
// 'this' refers to Gamer
this.playTime = 0;
// We use an ES6 arrow function
setInterval(() => {
// So 'this' still refers to the Gamer object
this.playTime++;
// Correctly outputs and incremented value representing play time in seconds
console.log( this.playTime );
@jaspervalero
jaspervalero / gist:53f38d9b413caa5846ca
Created March 5, 2015 05:12
ES5 example of 'this' scope using 'self' variable
function Gamer() {
// Store value of this in a variable
var self = this; // Some people use that or _this
self.playTime = 0;
// trackPlayTime() will now correctly auto increment every second
setInterval( function trackPlayTime() {
// Because we're using a variable we don't have to worry about the dynamic value of this in the new function scope
self.playTime++;
// Correctly out
@jaspervalero
jaspervalero / gist:0161b975e531666566fb
Last active August 29, 2015 14:16
ES5 this Example
function Gamer() {
// 'this' refers to Gamer
this.playTime = 0;
// We think trackPlayTime() will update a gamer's playtime every second
setInterval( function trackPlayTime() {
// But we're wrong because trackPlayTime() creates it's own version of 'this'
this.playTime++;
// Outputs NaN, because this.playTime was never cast as an integer in this scope
console.log( this.playTime );
@jaspervalero
jaspervalero / gist:d0acc37553b3d3c8fd8e
Last active August 29, 2015 14:16
ES6 Arrow Function Expression Example
// Multiple statements
([param] [,param]) => {
statements
}
// Single expression
param => expression
/* _____ Examples _____ */
@jaspervalero
jaspervalero / gist:38e75b65bc2358090d2d
Created February 20, 2015 05:40
My most used gitignore.io command
$ ignore osx,windows,linux,sublimetext,eclipse,node,grunt,bower,sass,jetbrains > .gitignore