software-tools-books / js4ds

JavaScript for Data Science
https://third-bit.com/js4ds/
Other
187 stars 32 forks source link

possible issue with objects snippet? #222

Open NickleDave opened 3 years ago

NickleDave commented 3 years ago

Hi and thank you for this really helpful book.

I think I might have spotted a very minor mistake in the OOP section? Under "classes" there's the following snippet: https://github.com/software-tools-in-javascript/js4ds/blob/a15c852e4b2df6d19380ee80075eb8cc5aeb6421/oop.tex#L211

for (let thing of everything) {
  const a = thing.area(thing)
  const p = thing.perimeter(thing)
  console.log(`${thing.name}: area ${a} perimeter ${p}`)
}

Notice the snippet shows passing the instance into itself (const a = thing.area(thing)).

But this is right after the text has gone to great lengths to explain that

Building every object by hand and calling thing.function(thing) is clumsy

and why you don't need to do that with classes.

I tested the snippet without passing thing into the method calls

for (let thing of everything) {
  const a = thing.area()
  const p = thing.perimeter()
  console.log(`${thing.name}: area ${a} perimeter ${p}`)
}

and it worked as expected.

Should those extra things be removed?