Skip to content

Instantly share code, notes, and snippets.

@jasdeepkhalsa
Created August 19, 2013 09:40
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 jasdeepkhalsa/6267405 to your computer and use it in GitHub Desktop.
Save jasdeepkhalsa/6267405 to your computer and use it in GitHub Desktop.
Façade pattern in JavaScript by Addy Osmani
var module = (function() {
var _private = {
i:5,
get : function() {
console.log( "current value:" + this.i);
},
set : function( val ) {
this.i = val;
},
run : function() {
console.log( "running" );
},
jump: function(){
console.log( "jumping" );
}
};
return {
facade : function( args ) {
_private.set(args.val);
_private.get();
if ( args.run ) {
_private.run();
}
}
};
}());
// Outputs: "current value: 10" and "running"
module.facade( {run: true, val:10} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment