I am having some problems to understand how to implement and use classes with private/ public methods and use it, even after some read around.
I have the following code:
var _Exits = 0;
var _Shuttles = 0;
function Parking(_str)
{
var Floors = 0;
var str = _str;
var Components = null;
function process ()
{
var Exit = new Array();
Exit.push("exit1" + str);
Exit.push("exit2");
var Shuttle = new Array();
Shuttle.push("shuttle1");
Shuttle.push("shuttle2");
Components = new Array();
Components.push(Exit, Shuttle);
}
function InitVariables()
{
var maxFloors = 0;
_Exits = (Components[0]).length;
_Shuttles = (Components[1]).length;
/*
algorithm calculates maxFloors using Componenets
*/
Floors = maxFloors;
}
//method runs by "ctor"
process(str);
InitVariables();
alert(Floors);
}
Parking.prototype.getFloors = function ()
{
return Floors;
}
var parking = Parking(fileString);
alert("out of Parking: " + parking.getFloors());
I want "process" and "InitVariables" would be private methods and "getFloors" would be public method, while "Floors", "str" and "Components" would be private vars. I think I made the variable private and "process" and "InitVariables" private, but no success with "getFloor" method.
Right now, "alert(Floors);" shows me the right answer while "alert(Floors);" doesn't show anything. My questions: 1. How can I inplement "getFloors"? 2. Did I write the code well or I should change it?