javascript-questions icon indicating copy to clipboard operation
javascript-questions copied to clipboard

Question 11, could be better

Open eddig opened this issue 7 years ago • 3 comments

There are a few things I noticed.

  1. Typo in the description: lydia.getFullName() should be member.getFullName()
  2. I'm not sure what do you mean under would have made lydia.getFullName() work, but I think it still doesn't do what you expect because of Question 3. The arrow function executes not in the member context and you won't see the full name. In the same time Person.prototype.getFullName = function() { return this.firstName + ' ' + this.lastName } should work as expected.

eddig avatar Jun 14 '19 07:06 eddig

I'm not sure what do you mean under would have made member.getFullName() work

I guess she means: would have returned "Lydia Hallie"

mindsers avatar Jun 14 '19 15:06 mindsers

Thank you so much for bringing this up! This is a great point that I unfortunately totally missed. I have updated the question and the explanation of the question. 👍

lydiahallie avatar Jun 15 '19 15:06 lydiahallie

@lydiahallie Hello, and thank you for this amazing job!

Regardless this question... I think that the answer to that still can be improved.

You can't add properties to a constructor like you can with regular objects. But we can. We can add any properties on function object, including functions that became a static methods.

If you want to add a feature to all objects at once, you have to use the prototype instead. If the goal is to show how you can add shared functionality that any instances can use, I think there is a need to add few more sentences to make it clear: shared functionality go to .prototype and static functionality go to the constuctor function itself.

Suruat avatar Aug 06 '19 08:08 Suruat