Example of self execution module that allows for method chaining.
// example of self execution module that allows fpr method chaining.
var obj = (function(val){
var i = 0;
//private
var add = function(val){
i += val;
return this // need this for chaining
};
//private
var subtract = function(val){
i -= val;
return this // need this for chaining
};
// private
var print = function(){
console.log(i);
return this; // need this for chaining
}
return { // makes these public
add: add,
subtract:subtract,
print: print
}
})();
obj.add(7).print().subtract(2).print();
console.dir(obj);