Skip to content

Instantly share code, notes, and snippets.

@g-akshay
Last active February 22, 2017 15:01
Show Gist options
  • Select an option

  • Save g-akshay/17d03703eb0ac2ee7b467eec342317b3 to your computer and use it in GitHub Desktop.

Select an option

Save g-akshay/17d03703eb0ac2ee7b467eec342317b3 to your computer and use it in GitHub Desktop.
Facade pattern
var myModule = (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"
myModule.facade( {run: true, val: 10} );
  • simplifies the API being presented to other developers, something which almost always improves usability
  • jQuery uses thispattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment