Skip to content

Instantly share code, notes, and snippets.

@gipi
Created November 22, 2011 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gipi/1385644 to your computer and use it in GitHub Desktop.
Save gipi/1385644 to your computer and use it in GitHub Desktop.
Create a module in Javaascript
var basketModule = (function() {
var basket = []; //private
return { //exposed to public
addItem: function(values) {
basket.push(values);
},
getItemCount: function() {
return basket.length;
},
getTotal: function(){
var q = this.getItemCount(),p=0;
while(q--){
p+= basket[q].price;
}
return p;
}
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment