Skip to content

Instantly share code, notes, and snippets.

@yashprit
Created May 30, 2014 06:49
Show Gist options
  • Save yashprit/be0fb5524647bf53f9fc to your computer and use it in GitHub Desktop.
Save yashprit/be0fb5524647bf53f9fc to your computer and use it in GitHub Desktop.
facade implementation in JavaScript, Taken from Addy Osmani blog on design pattern
var plugin = (function() {
var _implementation = {
id: 5,
get: function () {
return this.id;
},
set: function (_id) {
id = _id;
},
run: function () {
for(var i = 0; i < 5; i++) {
console.log(i + " -- " + this.get() + " running");
}
this.jump();
},
jump: function () {
console.log("I am some other method");
}
};
return {
facade: function (args) {
_implementation.set(args.val);
if(args.run) {
_implementation.run();
}
}
}
}());
plugin.facade({run:true, val:10})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment