marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 795 forks source link

Ch. 7 – Persistent group exercise hint #401

Closed mikegowen closed 6 years ago

mikegowen commented 6 years ago

Shouldn't this...

To add a property (empty) to a constructor that is not a method, you have to add it to the constructor after the class definition, as a regular property.

be this...

To add a property (empty) to a class that is not a method, you have to add it after the constructor in the class definition, as a regular property.

I may be totally misunderstanding. If so, ignore.

mikegowen commented 6 years ago

Also, separately. I'm not sure I understand the need for the empty property. Why not just create them normally?

let newGroup = new PGroup(collection);

Also, could you do this instead of the way you define the empty property?

static get empty() {
  return new PGroup;
}
marijnh commented 6 years ago

The property is added to the constructor function. Whether that is the same as the "class" is another discussion, but "constructor" is more specific in this case.

Why not just create them normally?

You could, but that's not the interface the exercise is asking you to implement.