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

completed first approach #451

Merged
merged 3 commits into from
Sep 17, 2022
Merged

completed first approach #451

merged 3 commits into from
Sep 17, 2022

Conversation

sofiichuk
Copy link
Contributor

a tiny js world: first approach

Demo |
Code base

The code is submitted in a dedicated feature branch.

Only code files are submitted.

Please, review.

@github-actions
Copy link

github-actions bot commented Sep 5, 2022

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 -- (pre-OOP) exercise check list

Relates to Object-Oriented JavaScript task.

Check-list - definition of done

  • Code is DRY, which means that whenever you see a pattern in your code those should be eliminated as much as possible. Examples:
    • print(dog); print(cat); etc ... should be refactored employing Array.forEach as the least
    • `${obj.legs}; ${obj.name}; etc...` (yes, strings are also code) must be refactored employing appropriate Array methods
  • Object methods like keys, values, entries shouldn't be used when a particular order is required as these do not guarantee any particular order of keys/values. Same refers to for...of and for...in when applied to objects.
    Hint: List explicitly the properties used to form an object presentation string.
  • Men and women belong to the same biological species.
  • ES6 class or prototype-based OO syntax aren't used.

Universal recommendations:

  • Give variables and functions meaningful names. Avoid generic names like item, element, key, object, array or their variations. Exception: helper functions that are specifically and intentionally designed to be multipurpose.
  • Function names should start with a verb as they denote actions; variables are normally nouns; boolean variables/functions start with is, does, has etc; variable containing multiple entities and functions returning lists contain entity name in plural form.
  • Have consistent code style and formatting. Employ Prettier to do all dirty work for you.
  • Use common sense or seek for an advice whenever requirements look ambiguous or unclear.

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,
Submissions Kottachecker 😺

@sofiichuk
Copy link
Contributor Author

checked

Copy link

@yaripey yaripey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, what happened to your Catwoman O? Why is she so undefined. Define her or something. Jokes aside, there is a problem with her saying. Task asks you to make it so Catwoman says the same that cat says ANYTIME. But in your current implementation changing the cat's saying doesn't change Catwoman's one, does it?

@yaripey yaripey self-assigned this Sep 12, 2022
@sofiichuk
Copy link
Contributor Author

sofiichuk commented Sep 13, 2022

hi!

saying: cat.saying does work indeed)
you could check it (in the console) here: https://codepen.io/sofiichuk/pen/ZEopPxW?editors=0010

although i could've changed it by the means of inheritance (as i did here - https://github.com/sofiichuk/a-tiny-JS-world/blob/OOP-exercise/index.js).
but the goal was - to do it without learning OOP approach (i had been unaware of that moment) - and so did i.

do i have to change anything yet?

@yaripey
Copy link

yaripey commented Sep 15, 2022

Well yes, your catwoman does say what the cat initially says, but that's why I marked ANYTIME in my comment. Consider this:

const cat = { saying: "First test" };
const catwoman = { saying: cat.saying };
console.log(catwoman.saying) // this will be "First test"
cat.saying = "Second test";
console.log(catwoman.saying) // this should be "Second test", but with your implementation, it will still be "First test"

So you need to find a way to connect those values in some way. And yes, for the means of this task, without using classes syntax.

@sofiichuk
Copy link
Contributor Author

sofiichuk commented Sep 16, 2022

spent so much time...
why hadn't you told me how to solve it?!
fixed that finally

Copy link

@yaripey yaripey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GJ, it works, but please check my comment below and keep it in mind in the future.

friends: 'undefined'
};

Object.setPrototypeOf(catWoman, cat);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the second time I see Object.setPrototypeOf, did anyone tell you to use it? Specs say it is a very slow method and there is an alternative - Object.create(). Or you could've used bind. Anyway, keep these in mind.

Copy link
Contributor Author

@sofiichuk sofiichuk Sep 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at first i tried to transform cat.saying to an object/array to pass it by reference;
then i tried to combine cat and catwoman props using object.assign;
i failed with both;
then i found out people handle stuff like this with a _proto_;
but i had already known of _proto_ as a (kind of) method not recommended to use in explicit way;
so i continued searchin for smth similar as a substitution;
nth-google-request was "set prototype" and it led to setPrototype;
(and now i see it's no better than using _proto_ - but afterwards)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, nice research)

@yaripey yaripey merged commit 05d7138 into kottans:main Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants