Last active
December 13, 2015 18:09
-
-
Save nephilim/4953315 to your computer and use it in GitHub Desktop.
Created to demonstrate one of possible problems with a sample code in chapter four of the book Javascript Patterns. For more information, refer to an example on page 92 of the book.
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 func = function() { | |
if ( !func.cache ) { | |
console.log("cache initialized @" + new Date()); | |
func.cache = "complex result"; | |
} | |
return func.cache; | |
}; | |
var func2 = func; | |
func2(); | |
// cache initialized | |
// "complex result" | |
func2(); | |
// "complex result" | |
func(); | |
// "complex result" | |
func = function() { | |
console.log("another"); | |
}; | |
func(); | |
func2(); | |
//cache initialized | |
//"complex result" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment