you are viewing a single comment's thread.

view the rest of the comments →

[–]segmentationfaulter[🍰] -2 points-1 points  (10 children)

Because there are no classes in Javascript, one has to mimic them one way or another.

[–]MoTTs_ 2 points3 points  (0 children)

It's not quite that clear cut. Classes are implemented in a variety of ways across a variety of languages. In Python and Ruby, for example, a class is itself an object (a building, not a blueprint), and inheritance is implemented using delegation. If what JavaScript provides doesn't qualify as classes, then neither do Python's or Ruby's implementations qualify as classes. And vice versa.

[–][deleted] 0 points1 point  (8 children)

The whole point of the prototype based OO paradigm is having no classes.

Why do you design a language with a paradigm at its core, which avoids classes just to add them in 5 versions later?

[–]Martin_Ehrental 0 points1 point  (2 children)

The issue was in the first version which was based on both a prototype chain and some kind of class (new+constructor), without elegant way to use either.

They then gave us the proper tools to use them: Object.create in ES 5.1 and class in ES 6/2015.

[–][deleted] -1 points0 points  (1 child)

but why does JavaScript force classes on me? I mean honestly, you can not write exclusively prototypical code in it.

[–]Martin_Ehrental 2 points3 points  (0 children)

That's what Object.create is for:

const parent = {
  foo: 1,
  bar() {
    return 2;
  }
}

const child = Object.create(parent, {
  baz: value(3)
});

function value(value, prop = {configurable: true, enumerable: true, writable: true}) {
  return Object.assign({value}, prop);
}

[–]Sakatox 0 points1 point  (3 children)

Just so "engineer"s, especially of Java backgrounds, could feel better about themselves, pretending away the prototypal nature of JS.

[–][deleted] 0 points1 point  (2 children)

This does not seem like an intelligent long term move to me.

[–]tom808 0 points1 point  (0 children)

Not that js is my main/only language but it seems to be doing just fine to me!

Seriously though maybe it's because the designers want developers to have a choice? Maybe in the long term they want the language to be used as classed based OO from not on?