loading...

Discussion on: JavaScript and Object-Oriented Programming

Collapse
oxyyyyy profile image
Alexandr Vlasenko

Nice article!
But it seems you've got a mistake in this code block:

function Book(_name, _price, _author) {
  Product.call(this, _name, _price);
  const author = _author; // <- here
}

it should be like:

function Book(_name, _price, _author) {
  Product.call(this, _name, _price);
  this.author = _author; // <- here
}
Collapse
rainerhahnekamp profile image
rainerhahnekamp Author

Hi Alexandr, thanks for mentioning but I did this on purpose to enforce encapsulation. So I don't want that anybody can access the author property except the object itself.

I am using this in prototype-based version at the end of this article and mentioned the problem with encapsulation.

Collapse
oxyyyyy profile image
Alexandr Vlasenko

You're right in this case
sry :]

Collapse
avalander profile image
Avalander

Still, it's entirely useless, you should add a getter or something to avoid confusing people :)

Thread Thread
rainerhahnekamp profile image
rainerhahnekamp Author

True, have added a getter method. Thanks for the input to both of you!