Is the following code equivalent to a class with associated functions? What is the difference between 'obj.start' function and startEngine() function? (Not logic wise, structural wise.. )
var Car = function (carElement)
{
var obj = {},
isRunning = false,
dashboard,
speed = 0,
accelerometer,
gearElement,
transmission =
{
'first': { ts: 15, rpm: 2 },
'second': { ts: 30, rpm: 4 },
'third': { ts: 50, rpm: 5 },
'fourth': { ts: 80, rpm: 5 },
'fifth': { ts: 110, rpm: 6 }
};
function startEngine()
{
//some code to start engine
}
obj.start = function ()
{
//more code..
}
obj.stop = function ()
{
//even more code...
};
(function init()
{
obj.start();
}());
return obj;
};
[EDIT] This question practically describes what my question is all about
obj.startis assigned a function and can be later accessed using obj.start(), however, it does not answer why one would use that instead of a function with anormalheaderfunction startEngine().. and is Car considered to be a class here? Thanks