ruk·si

🍦 JavaScript Pattern
Facade

Updated at 2015-05-13 16:11
var curtain = (function() {

  var wiggle = function() {
    console.log('Curtain wiggles.');
  };

  var makeWet = function() {
    console.log('Curtain gets wet.');
  };

  var makeDry = function() {
    console.log('Curtain gets dried.');
  };

  return function(state) {
    state = state || {};
    if (state.wind) {
      wiggle();
    }
    if (state.sun && !state.rain) {
      makeDry();
    }
    if (!state.sun && state.rain) {
      makeWet();
    }
  };
}());

curtain({rain: true, sun: true, wind: true});
curtain({rain: true});
curtain({sun: true, wind: true});
curtain();