-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
tiny-js-oop #439
tiny-js-oop #439
Conversation
Hey! Congratulations on your PR! 😎😎😎 Let's do some self-checks to fix most common issues and to make some improvements to the code before reviewers put their hands on the code. Go through the requirements/most common mistakes listed/linked below and fix the code as appropriate. If you have any questions to requirements/common mistakes feel free asking them here or in Students' chat. When you genuinely believe you are done put a comment stating that you have completed self-checks and fixed code accordingly. Also, be aware, that if you would silently ignore this recommendation, a mentor can think that you are still working on fixes. And your PR will not be reviewed. 😒 A Tiny JS World -- OOP exercise check listRelates to A Tiny JS World OOP exercise. Check-list - definition of doneMinimal requirements to meet:
Optional level up (not required to implement):
Bonus:
Helpful resources: Universal recommendations:
Also take a note of the requirements above and follow them in all your future projects. By the way, you may proceed to the next task before this one is reviewed and merged. Sincerely yours, |
Self-check has been done. Everything should be ok. |
This issue has been automatically marked as stale because there were no activity during last 14 days. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. А. Чому так? Б. Що робити, якщо в піарі нема оновлень, оскільки не зрозуміло, що треба зробити? В. А якщо я все зробив(ла) і це ментор не рев'юває мої зміни?
Г. Хіба недостатньо того, що я додав(ла) коміт із змінами? Традиційна пропозиція: задай питання по вищенаписаному в студентському чаті. |
Self-check has been done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yasya23 good job!
A couple of improvements and we are done.
constructor(species, name, gender, saying) { | ||
super(species, name, gender); | ||
this.paws = 4; | ||
this.saying = saying; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What makes saying
different from name
in terms of generalization into the base class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, thanks for checking! There is no difference in these cases, fixed it.
} | ||
|
||
showProperties() { | ||
return `${this.species}; ${this.name}; ${this.gender}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and similar fragments below:
Benefit from Array
methods. This will make code DRYer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected for an array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yasya23 nearly there
inhabitants.forEach(function (inhabitant) { | ||
print(inhabitant.showProperties()); | ||
print(inhabitant.showProperties().join("; ")); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arrow functions will make code less verbose.
Compare:
inhabitants.forEach(function (inhabitant) {
print(inhabitant.showProperties().join("; "));
});
inhabitants.forEach(inhabitant => print(inhabitant.showProperties().join("; ")));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking. Yes, it looks much better, fixed it.
return `${super.showProperties()}; ${this.hands}; ${this.legs}; ${ | ||
this.saying | ||
}`; | ||
return [...super.showProperties(), this.hands, this.legs, this.saying]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and line 32 below:
- repetition
- also a shared property should be handled by the class that owns it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it but I`m not sure about my decision. If it's incorrect please give me advice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good start.
Your previous method version returned a string. Now it returns array not joined into string. Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused. The join method returns a string from the array of elements. If I add it here then it will return a string.
showProperties() { return [ ...super.showProperties().slice(0, 3), this.paws, ...super.showProperties().slice(3, 4), ].join("; "); }
But I don’t understand the difference, because at the end I still iterate over the array and add a join.
inhabitants.forEach(inhabitant => print(inhabitant.showProperties().join("; ")));
Apparently, there is something I don't understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My question was about reasons behind changing from string to array. It is a significant change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both approaches may be valid. Want to understand reasoning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of that post)
This and similar fragments below:
Benefit from Array methods. This will make code DRYer.
For myself, I realized that I need to create an array instead of a string. But now I understand that I could iterate through the array of values using the map method and add a join, and not write a semicolon after each value. Something like this.
["species", "name", "gender", "saying"] .map((property) => this.property) .join("; ");
Only working with an array for me here looks easier if I want to insert a value in its middle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yasya23 great job done!
...super.showProperties().slice(0, 3), | ||
this.hands, | ||
this.legs, | ||
...super.showProperties().slice(3, 4), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize why slicing.
Just notice that this is not a really good approach. Why? A: This means that a developer working on Human
or any other subclass would need to know what is the right order of props in the base class. Likewise, developer working on Inhabitants
class (e.g. add a property between already existing) should be aware their changes may affect subclasses' behavior. On big projects it is not feasible. Ideally, every class handles its own properties and unaware of other classes internals.
P.S. BTW, class names by convention are singular unless they really contain multiple instances of anything.
OOP classes
Demo |
Code base
The code is submitted in a dedicated feature branch.
Only code files are submitted.
Please, review.