Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible issue with objects snippet? #222

Open
NickleDave opened this issue Nov 2, 2021 · 0 comments
Open

possible issue with objects snippet? #222

NickleDave opened this issue Nov 2, 2021 · 0 comments

Comments

@NickleDave
Copy link

NickleDave commented Nov 2, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant