What are the benefits of a classical structure over a prototyple one?
- by Rixius
I have only recently started programming significantly, and being completely self-taught, I unfortunately don't have the benefits of a detailed Computer science course. I've been reading a lot about JavaScript lately, and I'm trying to find the benefit in classes over the prototype nature of JavaScript. The question seems to be drawn down the middle of which one is better, and I want to see the classical side of it.
When I look at the prototype example:
var inst_a = {
"X": 123,
"Y": 321,
add: function () {
return this.X+this.Y;
}
};
document.write(inst_a.add());
And then the classical version
function A(x,y){
this.X = x;
this.Y = y;
this.add = function(){
return this.X+this.Y;
};
};
var inst_a = new A(123,321);
document.write(inst_a.add());
I begun thinking about this because I'm looking at the new ecmascript revision 5 and a lot of people seem up in arms that they didn't add a Class system.