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

Lesson-20: functional programming #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Lesson-20: functional programming #2

wants to merge 2 commits into from

Conversation

lena1687
Copy link
Owner

No description provided.

originalTeam: LeadOfTeam
): LeadOfTeam => {
const obj = { ...originalTeam };
obj.captain.age = 28;

Choose a reason for hiding this comment

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

Здесь происходит мутация внутреннего объекта (captain), как я понимаю. Потому что на 31 строке копирование поверхостное, не глубокое (то есть поле captain скопировалось в новый объект по ссылке, и указывает на поле captain из оригинального объекта).

Чтобы этого избежать, поле captain тоже нужно копировать:

export const originalTeamToExpectedTeamDeep = (originalTeam: Team): Team => {
  const { captain } = originalTeam;
  return { ...originalTeam, captain: { ...captain, age: 28 } };
};

Choose a reason for hiding this comment

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

Спасибо за комменты)

@AntiHero, jsdom: [Bug]: structuredClone is not defined #3363
jsdom/jsdom#3363

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

Successfully merging this pull request may close these issues.

None yet

3 participants