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
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)); |
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
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 |
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
var foo = () => console.log("foo"); | |
// similar to | |
var bar = function(){ | |
console.log('bar'; | |
} | |
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
function Aaron(){ | |
this.favoriteSaying = "I love Google!"; | |
//this.saySomething = function(){ | |
// console.log(this.favoriteSaying); | |
//} | |
this.saySomething = () => { | |
console.log(this.favoriteSaying); | |
} | |
} |
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
// 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!" |
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
// 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!" |
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
// 2. Objects | |
function Foo(){ | |
this.bar = function(){ | |
console.log(this); | |
} | |
return this; | |
} | |
new Foo().bar(); //logs a new Foo object |
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
// 1. GLOBAL THIS (ie: window object) | |
console.log(this); | |
function foo(){ | |
console.log(this); //logs the window object | |
} | |
foo(); |
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
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. | |
*/ |
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
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){ | |