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
run(); | |
var run = function(){ | |
console.log(“running”); | |
} | |
run(); |
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 run = undefined; | |
run(); //error, since undefined isn’t a function | |
run = function(){ | |
console.log(“running”); | |
} | |
run(); |
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 foo = 0; | |
if(true){ | |
let bar = 1; | |
} | |
console.log( foo + bar ); | |
//results in runtime error, bar is not defined |
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 a = 0; | |
if(true){ | |
let a = 2; | |
console.log(“here a = “,a); | |
} | |
console.log(“at the end a = “,a); |
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){ | |
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
// 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
// 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
// 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
// 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!" |