Skip to content

Instantly share code, notes, and snippets.

@tarun-nagpal-github
Last active July 10, 2018 05:58
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 tarun-nagpal-github/92da292e1fa453cd5dfd603c1c6dc2ef to your computer and use it in GitHub Desktop.
Save tarun-nagpal-github/92da292e1fa453cd5dfd603c1c6dc2ef to your computer and use it in GitHub Desktop.
Revealing Module Design Pattern
/**
*
* @param {number} x
* @param {number} y
*
* @returns function
*/
var Calculator = (function(){
var _privateVariable = 100;
//Private function
function _privateFunction(x, y){
return (x*x) + (y *y);
}
function sum(x, y){
return x + y;
}
function mul(x, y){
return x * y;
}
function divide(x, y){
return x / y;
}
function square(x, y) {
return _privateFunction(x, y);
}
// functions are revelied here
return {
sum : sum,
mul : mul,
divide : divide,
square: square
}
})();
var cal = Calculator;
console.log(cal.sum(2,3));
console.log(cal.mul(2,3));
console.log(cal.divide(2,3));
console.log(cal.square(2,3));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment