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.
Inheritance is not really possible without using the psuedoclassical style. See what Douglas Crockford has to say about it. Even if you were to use a purely prototypal object structure, you'd have to create a constructor function for inheritance (which Crockford does, then abstracts it behind a create
method then calls it purely prototypal)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With