Last active
August 29, 2015 14:02
-
-
Save tmathews/13d929c48e39e2d49c29 to your computer and use it in GitHub Desktop.
This file contains 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
// Define modules. | |
need("cookie", function ( need ){ | |
function Cookie ( type ) { | |
this.type = type; | |
} | |
Cookie.prototype.getName = function () { | |
return this.type + " Cookie"; | |
} | |
return Cookie; | |
}); | |
need("generate-cookie", function ( need ) { | |
var Cookie = need("cookie"); | |
return function generateCookie () { | |
return new Cookie("Chocolate Chip"); | |
} | |
}); | |
// Define need function. | |
function need ( key, value ) { | |
if ( !need.cache ) need.cache = {}; | |
if ( value ) { | |
need.cache[key] = { create: value }; | |
return; | |
} | |
var obj = need.cache[key]; | |
if ( !obj ) return; | |
if ( !obj.value ) obj.value = obj.create(need); | |
return obj.value; | |
} | |
// Use it. | |
var generator = need("generate-cookie"); | |
var cookie = generator(); | |
console.log(cookie.getName()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment