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

Добавляет ответ на вопрос об отличиях rest и spread #5180

Merged
merged 5 commits into from Apr 2, 2024

Conversation

iren-a
Copy link
Contributor

@iren-a iren-a commented Feb 24, 2024

Описание

Добавила ответ на вопрос "В чём отличия rest и spread операторов?".

Closes #4192

Чек-лист

  • Текст оформлен согласно руководству по стилю
  • Ссылки на внутренние материалы начинаются со слеша и заканчиваются слэшем либо якорем на заголовок (/css/color/, /tools/json/, /tools/gulp/#kak-ponyat)
  • Ссылки на картинки, видео и демки относительные (images/example.png, demos/example/, ../demos/example/)

@TatianaFokina TatianaFokina added js Контент по JavaScript собеседование Контент для На собеседовании labels Feb 26, 2024

Оператор `rest` всегда должен идти последним и использоваться только один раз в рамках одной деструктуризации или объявлении параметров функции.

#### Что делает оператор`spread`?
Copy link
Contributor

Choose a reason for hiding this comment

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

возможно не хватает пробела между словами оператор и spread
(если сравнить выше по аналогии с оператор и rest)

Copy link
Member

Choose a reason for hiding this comment

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

Все так

Suggested change
#### Что делает оператор`spread`?
#### Что делает оператор `spread`?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

исправила

console.log(first, second, third);
}
const array = [1, 2, 3, 4, 5];
doSomething(...array); // 1 2 3
Copy link
Contributor

@splincool splincool Mar 27, 2024

Choose a reason for hiding this comment

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

вот тут не совсем согласен с комментарием // 1 2 3, потому что складывается впечатления, что в функцию попадут только значения 1, 2, 3 как будто вот так doSomething(1, 2, 3)
А на самом деле будет вот так doSomething(1, 2, 3, 4, 5), но в самой функции будет взяты только первые 3 значения

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Спасибо, убрала лишние параметры из примера, чтобы не путать.

Copy link
Member

@HellSquirrel HellSquirrel left a comment

Choose a reason for hiding this comment

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

Классно, спасибо. Давай чуть-чуть подправим комменты )

console.log(c, object); // 3 {a: 1, b: 2}
```

Оператор `rest` всегда должен идти последним и использоваться только один раз в рамках одной деструктуризации или объявлении параметров функции.
Copy link
Member

Choose a reason for hiding this comment

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

Тут не совсем ясно. Можно это прочитать как делайте вот так { a, b, c...}
Можно починить уточнив что rest это префиксный оператор

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Переформулировала по-другому, с примером.
Про префиксный оператор добавила сначала, но потом убрала, мне показалось, что тогда непонятно, только ли rest префиксный, или все-таки оба.


Оператор `rest` всегда должен идти последним и использоваться только один раз в рамках одной деструктуризации или объявлении параметров функции.

#### Что делает оператор`spread`?
Copy link
Member

Choose a reason for hiding this comment

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

Все так

Suggested change
#### Что делает оператор`spread`?
#### Что делает оператор `spread`?

@HellSquirrel
Copy link
Member

Супер, добавила бейджик и мержу

Copy link

github-actions bot commented Apr 1, 2024

Превью контента из 7098dfd опубликовано.

@HellSquirrel HellSquirrel merged commit 06798d5 into doka-guide:main Apr 2, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js Контент по JavaScript собеседование Контент для На собеседовании
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ответ на вопрос: В чём отличия rest и spread операторов?
4 participants