Skip to content

Instantly share code, notes, and snippets.

@JasonDeving
Last active March 20, 2016 01:12
Show Gist options
  • Save JasonDeving/1795a838a309105284ed to your computer and use it in GitHub Desktop.
Save JasonDeving/1795a838a309105284ed to your computer and use it in GitHub Desktop.
module pattern
var Module = function(){
var privateProperty = 'foo';
function privateMethod(args){
// do something
};
return {
publicProperty: "",
publicMethod: function(args){
// do something
},
priviledgedMethod: function(args){
privateMethod(args);
}
};
};
// example car
var Car = function(){
var gasolineLevel = 10;
function useGas(amt){
if(gasolineLevel - amt < 0){
console.log("no more gase")
} else {
gasolineLevel -= amt;
}
}
return {
radiotStation: "104",
changeStation: function(station){
this.radioStation = station;
},
go: function(speed){ useGas(speed); }
}
};
var honda = Car();
honda.go(2);
honda.go(10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment