Skip to content

Instantly share code, notes, and snippets.

View aaronfrost's full-sized avatar
:octocat:
Software Architect Contractor

Aaron Frost aaronfrost

:octocat:
Software Architect Contractor
View GitHub Profile
@aaronfrost
aaronfrost / af10.js
Created March 23, 2013 07:50
Arrow Function - 10 - Multiple Lines need brackets
let add = (x,y)=> x+y;
console.log(add(1,2));
//NO BRACKETS FOR ONE LINES
let add = (x,y)=> {
if(x && y){
console.log(x + y);
}
}
console.log(add(1,2));
@aaronfrost
aaronfrost / af9.js
Created March 23, 2013 07:45
Arrow Function - 9 - Implicit return for one-liners
let add = (x,y)=> x+y;
console.log(add(1,2));
//When there is only line instruction
//in the Arrow Function body, you
//don't need the 'return' keyword
//to return the result of the expression
@aaronfrost
aaronfrost / af8.js
Created March 23, 2013 07:42
Arrow Function - 8 - Difference
var foo = () => console.log("foo");
// similar to
var bar = function(){
console.log('bar';
}
@aaronfrost
aaronfrost / af7.js
Created March 23, 2013 07:36
Arrow Function - 7 - Arrow Functions
function Aaron(){
this.favoriteSaying = "I love Google!";
//this.saySomething = function(){
// console.log(this.favoriteSaying);
//}
this.saySomething = () => {
console.log(this.favoriteSaying);
}
}
@aaronfrost
aaronfrost / af6.js
Last active December 15, 2015 07:58
Arrow Function - 6 - Me = this
// Problem with the current way. Closures explode!!!
function Aaron(){
var me = this; // or that, _this, self, etc
this.favoriteSaying = "I love Google!";
this.saySomething = function(){
console.log(me.favoriteSaying);
}
}
var a = new Aaron();
a.saySomething(); //logs "I love Google!"
@aaronfrost
aaronfrost / af5.js
Created March 23, 2013 07:24 — forked from anonymous/af5.js
// Problem with the current way. Closures explode!!!
function Aaron(){
this.favoriteSaying = "I love Google!";
this.saySomething = function(){
console.log(this.favoriteSaying);
}
}
var a = new Aaron();
a.saySomething(); //logs "I love Google!"
@aaronfrost
aaronfrost / af2.js
Created March 23, 2013 06:56
Arrow Function - 2 - Object
// 2. Objects
function Foo(){
this.bar = function(){
console.log(this);
}
return this;
}
new Foo().bar(); //logs a new Foo object
@aaronfrost
aaronfrost / af1.js
Last active December 15, 2015 07:49
Arrow Function - 1 - Global This
// 1. GLOBAL THIS (ie: window object)
console.log(this);
function foo(){
console.log(this); //logs the window object
}
foo();
@aaronfrost
aaronfrost / istailcall.js
Last active December 11, 2015 08:49
Question for Dave Herman.
function foo(){
var temp = bar();
return temp;
}
/*
Is this a tail call? the call to bar is not actually in tail position, however
it is the last instruction to execute before the return expression. Let me know.
*/
@aaronfrost
aaronfrost / gist:4460066
Last active December 10, 2015 16:18
This is the code that is faster than AJ's code
var thingsCount = 0;
var urls = []
, deferreds = []
;
var mainDeferred = $.Deferred();
deferreds.push(mainDeferred);
$.get('https://www.lds.org/directory/services/ludrs/unit/current-user-units/',function(r){