Created
March 12, 2014 17:21
-
-
Save IOZ/9511753 to your computer and use it in GitHub Desktop.
Modular js architecture
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
var MODULE = {}; | |
/* User page */ | |
MODULE.User = (function(module){ | |
var username = ''; | |
var methods = { | |
setName: function(name){ | |
username = name; | |
this.getName(); | |
}, | |
getName: function(){ | |
return username; | |
}, | |
userBio: function(){ | |
return this.getName(); | |
} | |
}; | |
return methods; | |
})(MODULE); | |
/* Cart page */ | |
MODULE.Cart = (function(module){ | |
var cart = []; | |
var methods = { | |
addItem: function(item){ | |
cart.push(item); | |
}, | |
cartCount: function(){ | |
return cart.length; | |
}, | |
cartTotal: function(){ | |
return this.cartCount() * 10; | |
}, | |
getUserName: function(){ | |
return module.User.userBio(); | |
} | |
}; | |
return methods; | |
})(MODULE); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment