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