Created
May 30, 2014 06:49
-
-
Save yashprit/be0fb5524647bf53f9fc to your computer and use it in GitHub Desktop.
facade implementation in JavaScript, Taken from Addy Osmani blog on design pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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