Facade: a superficial appearance or illusion of something: They managed somehow to maintain a facade of wealth.

Very interesting design pattern I cam across which provides protection of code and only exposure to those functions which you return from within the encapsulated object. Worth the share.

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();  
module.facade({ run: true, val: 10 }); //outputs current value: 10, running
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.

No Reader comments

Learn JavaScript for free!
Free course: Introduction to JavaScript

Yours when you take up a free 14-day SitePoint Premium trial.