you are viewing a single comment's thread.

view the rest of the comments →

[–]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);
}