JS modules chaining #2
advanced module pattern
by toubia95
HTML
<p id="result"></p>
CSS
/* http://singlepageappbook.com/maintainability1.html */
JavaScript
var res = document.getElementById("result");
var Fonc = Fonc || {};
(function() {
Fonc.Dec = function (x) {
this.dec = x;
return this;
};
Fonc.Mult = function (y) {
this.mult = y;
this.decmult = this.dec * y;
return this;
};
return Fonc;
})();
(function() {
Fonc.Display = function () {
if (this.decmult) {
return this.decmult;
} else if (this.dec) {
return this.dec;
} else if (this.mult) {
return this.mult;
} else {
return 0;
}
};
return Fonc;
})();
mult3 = Fonc.Dec(3).Mult(9).Display();
res.insertAdjacentHTML('beforeend', 'result: '+ mult3 + '<br>');