JSFiddle - React, Tailwind, and code Playground
by austinfrance
JavaScript
function Plus(n) {
// private data
var one = 1,
two = 2;
// private methods
function add(v) {
return n+v;
}
// public interface
return {
one: add(one),
two: add(two),
three: function() {
return n+3;
},
print: function() {
console.log(n);
console.log(this.one);
console.log(this.two);
console.log(this.three());
}
};
}
var plus = new Plus(1);
console.log(plus.one);
console.log(plus.two);
console.log(plus.three());
plus.print();
// new is not necessary using this pattern
plus = Plus(1);
console.log(plus.one);
console.log(plus.two);
console.log(plus.three());
plus.print();
debugger;