What are the benefits of a classical structure over a prototyple one?

Posted by Rixius on Stack Overflow See other posts from Stack Overflow or by Rixius
Published on 2010-05-21T15:25:33Z Indexed on 2010/05/21 15:40 UTC
Read the original article Hit count: 130

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.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about classes