I'm a newbie programmer, but I already saw some things that can be done better or at least differently. For example, classes are made available to create new objects, like this:
var newObject = new className(params);
But is this really necessary, since functions can return an object? I mean, with the following code you could as well get rid of the new keyword:
var newFruit = function (confobj) {
var instance = {};
//Common to all fruits
instance.edible = true;
//Custom settings
instance.color = confObj.color;
instance.shape = confObj.shape;
instance.sweetness = confObj.sweetness;
instance.sweet = (instance.sweetness > 0);
return instance;
};
var banana = newFruit({
color: 'yellow',
shape: 'long',
sweetness: 8
});
So, what do would be the advantages of using JS classes that require the new keyword instead of using code like that provided in the example?