JSFiddle - React, Tailwind, and code Playground
by benhowdle89
JavaScript
var myClass = function() {
var privateVar = 'do not look at me from the outside';
return {
publicVar: 'access me from anywhere',
fname: '',
init: function(fname) {
this.fname = (fname !== undefined) ? fname : 'guest';
console.log('you\'ve kicked this class off, ' + this.fname);
},
getPrivateVar: function() {
return privateVar;
}
};
}();
myClass.init(); // you've kicked this class off, guest
myClass.init('ben'); // you've kicked this class off, ben
console.log(myClass.publicVar); // access me from anywhere
console.log(myClass.privateVar); // undefined
console.log(myClass.getPrivateVar()); // do not look at me from the outside