JSFiddle - React, Tailwind, and code Playground
by dhoerster
HTML
Public and Private Members in Different Instances
<br/><hr/>
JavaScript
var AgileWays = AgileWays || {}; //not really necessary
AgileWays = function(fName, lName) {
//keep hold of this
var me = this;
//public "properties"
this.firstName = fName;
this.lastName = lName;
//private method
function getFullName() {
return me.firstName + " " + me.lastName;
}
//public method
this.fullName = function() { return getFullName(); };
};
//create two instances of AgileWays
var myAgile = new AgileWays("David", "Hoerster");
var myOtherAgile = new AgileWays("Joe", "Brown");
alert(myAgile.fullName());
alert(myOtherAgile.fullName());
//change a property of one instance...the second one is unaffected
myAgile.firstName = "Dave";
alert(myAgile.fullName());
alert(myOtherAgile.fullName());