JSFiddle - React, Tailwind, and code Playground
by rhodee
JavaScript
// function construtor with a public method
function MyApp() {
// this is a public setter
this.name;
}
// i constructed a new function object and passed in a value to the function constructor
var App = new MyApp();
App.name = 'Andre';
alert(App.name);
// I was able to set the title of the function object with the public setter
App.name = 'Rhodee';
alert(App.name);
function YourApp() {
// privately scoped variable
var privateName = 'Bob';
// privileged method
this.setName = function (x) {
privateName = x;
};
// privileged method
this.getName = function() {
return privateName;
};
}
var NewApp = new YourApp();
// returns undefined because the var privateName is scoped
alert(NewApp.privateName);
// we can get the name with a privileged method
alert(NewApp.getName());
// so lets set the name
NewApp.setName('George');
alert(NewApp.getName());