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

Exercise 3 troubles #54

Open
michaelgrilo opened this issue Sep 28, 2015 · 1 comment
Open

Exercise 3 troubles #54

michaelgrilo opened this issue Sep 28, 2015 · 1 comment

Comments

@michaelgrilo
Copy link

I was not able to take the line Player.super_.prototype.toString.call(this) and convert it to super.toString();. I had to pull up the solution. I've still got a way to go before I completely understand what's happening in Exercise 3, but is there a way the instructions could be written so it's slightly more obvious how to rewrite this line?

Additionally, it makes sense to make that we wouldn't need to include util since we rewrote that line, but how would I have known to start the script with 'use strict';?

@ShadowManu
Copy link

Just passing by to contribute: trying to disect the line you wrote just by programmer's instinct, we can deduce that the expression is trying to:

  1. Player: get the player object
  2. .super_: access the 'superclass'
  3. .prototype: but the class stuff (methods and the like) really lives in its prototype
  4. .toString: we access that superclass string method
  5. .call(this): and we try to use it on the actual object (by the expression context, it's the player)

So, resuming, we are just trying to use the superclass string method here in this context (the Player's context... again, on instinct, we could have come up with the solution super.toString(). Maybe a small hint on saying exactly that ('remember we are just trying to use the superclass string method') could prove useful.

Regarding the 'use strict';, it doesn't affect the correctness of the answer, but its considered a good practice to add it to every JS code you can. It basically tells the JS engine to not forgive sloppy code making it more robust and even secure. You can read a little more of it here on MDN

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

2 participants