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
<div id="fullpage"> | |
<div class="section"></div> | |
<div class="slide"></div> | |
<div class="slide"></div> | |
<div class="slide"></div> | |
</div> | |
</div> |
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
<div id="fullpage"> | |
<div class="section"></div> | |
<div class="section"></div> | |
<div class="section"></div> | |
<div class="section"></div> | |
</div> |
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 fib = memo(function(n) { | |
if (n < 2){ | |
return 1; | |
}else{ | |
//We'll console.log a loader every time we have to recurse | |
console.log("loading..."); | |
return fib(n-2) + fib(n-1); | |
} | |
}); |
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 memo(func){ | |
var cache = {}; | |
return function(){ | |
var key = JSON.stringify(arguments); | |
if (cache[key]){ | |
console.log(cache) | |
return cache[key]; | |
} | |
else{ | |
val = func.apply(null, arguments); |
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
// A more functional memoizer | |
//We can beef up our module by adding functions later | |
var Memoizer = (function(){ | |
//Private data | |
var cache = {}; | |
//named functions are awesome! | |
function cacher(func){ | |
return function(){ | |
var key = JSON.stringify(arguments); |
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 memo(func){ | |
var cache = {}; | |
return function(){ | |
var key = JSON.stringify(arguments); | |
if (cache[key]){ | |
console.log(cache) | |
return cache[key]; | |
} | |
else{ | |
val = func.apply(null, arguments); |
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
//Knowing that we have access to whatever | |
//the user inputs into our function expression, we then write... | |
return function(){ | |
var key = JSON.stringify(arguments); | |
if (cash[key]){ | |
return cache[key]; | |
} | |
else{ | |
//apply() comes in handy here and will simply |
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
/* | |
Closures cannot access the arguments object of the parent, | |
but, because functions are first class objects, we can pass a function as a parameter. | |
The closure can now access the arguments object of the function that is passesd as a parameter. | |
So, there is no confusion as to which arguments object we want the closure to access. | |
We're basically taking advantage of its limitations | |
*/ | |
function demoMemo(func){ | |
//we must return a function in order to keep state | |
//this will be more apparant in a recursive example |
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 zombieOne = (function(){ | |
//private variables | |
var firstName = ""; | |
var lastName = ""; | |
//private functions | |
function init(data){ | |
firstName = data.firstName; | |
lastName = data.lastName; | |
} | |