René's URL Explorer Experiment


Title: [Предложение: учебник]: `yield*` тоже работает в две стороны · Issue #1934 · javascript-tutorial/ru.javascript.info · GitHub

Open Graph Title: [Предложение: учебник]: `yield*` тоже работает в две стороны · Issue #1934 · javascript-tutorial/ru.javascript.info

X Title: [Предложение: учебник]: `yield*` тоже работает в две стороны · Issue #1934 · javascript-tutorial/ru.javascript.info

Description: Описание После прочтения главы учебника про Генераторы мне стала интересна эта тема я и решил уделить чуть больше внимания, чем на остальные темы. И в конечном итоге я нашел одну особенность, которая не была упомянута в данной главе и ко...

Open Graph Description: Описание После прочтения главы учебника про Генераторы мне стала интересна эта тема я и решил уделить чуть больше внимания, чем на остальные темы. И в конечном итоге я нашел одну особенность, котор...

X Description: Описание После прочтения главы учебника про Генераторы мне стала интересна эта тема я и решил уделить чуть больше внимания, чем на остальные темы. И в конечном итоге я нашел одну особенность, котор...

Opengraph URL: https://github.com/javascript-tutorial/ru.javascript.info/issues/1934

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Предложение: учебник]: `yield*` тоже работает в две стороны","articleBody":"### Описание\r\n\r\nПосле прочтения главы учебника про [Генераторы](https://learn.javascript.ru/generators) мне стала интересна эта тема я и решил уделить чуть больше внимания, чем на остальные темы. И в конечном итоге я нашел одну особенность, которая не была упомянута в данной главе и которую на мой субъективный взгляд стоит добавить.\r\n\r\nВ главе было рассказано про то, что оператор `yield` работает в две стороны - при вызове метода `next` у генератора оператор возвращает значение справа, а если в метод `next` передать значение, то оно будет передано части слева от оператора `yield`.\r\n\r\nТак вот, тоже самое работает и при композиции генераторов с использованием оператора `yield*`. Когда вложенный генератор завершает свое выполнение, выполнив последний `yield`, он ждет следующего вызова `next` и уже после исполнение переходит в генератор на уровень выше. Но я заметил, что если прописать после последнего `yield` оператор `return` с каким либо значением, то есть передать его на уровень выше, а во внешнем генераторе прописать что то типа `let data = yield* generator_func()`, то можно принять возвращенное значение.\r\n\r\nПример:\r\n```js\r\nfunction* f() {\r\n    yield 2;\r\n    return 3;\r\n}\r\n\r\nfunction* g() {\r\n    yield 1;\r\n    let data = yield* f();\r\n    // тут выполняются некоторые необходимые преобразования значения data\r\n    yield data;\r\n}\r\n\r\nlet gen = g();\r\ngen.next().value; // 1\r\ngen.next().value; // 2\r\ngen.next().value; // 3\r\n```\r\n\r\n### Мотивация\r\n\r\nЯ считаю, что для глубокого понимания концепции композиции генераторов нужно знать о вышеописанной особенности.\r\n\r\nВ доказательство могу еще привести такой пример. Я попытался реализовать систему сценариев поведения телеграмм бота через генераторы. Все сообщения от пользователя передавались в уникальный для каждого генератор, а полученные значения из этого генератора передавались как сообщения от бота пользователю. В итоге я пришел к выводу, что нужно как то передавать последнее значение `yield` в генератор уровнем выше. Так и открыл для себя данную особенность композиции генераторов в JavaScript.\r\n\r\nВот пример кода одного из сценариев:\r\n```js\r\n// Пример сценария-генератора\r\nexport default function* () {\r\n    let num1 = Number( yield `Введите первое число` );\r\n    if (isNaN(num1)) {\r\n        return yield \"[1] Извините, это не число. Повторите попытку\"\r\n    }\r\n    let num2 = Number( yield `Введите второе число` );\r\n    if (isNaN(num2)) {\r\n        return yield \"[2] Извините, это не число. Повторите попытку\"\r\n    }\r\n    return yield `Сумма ваших чисел: ${ num1 + num2 }`\r\n}\r\n```\r\n\r\n\r\n\r\n### Готовы ли вы принять участие в реализации данного предложения?\r\n\r\nДа, я готов(а) принять участие.","author":{"url":"https://github.com/Smail000","@type":"Person","name":"Smail000"},"datePublished":"2024-02-23T12:31:44Z","url":"https://github.com/javascript-tutorial/ru.javascript.info/issues/1934"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f3fefb3c-86b5-404c-7b2f-c78b580cc0f0
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id87E8:1F6A:25953F:32486C:6AFBE52F
html-safe-nonced3b32893058dea75d851fb1ec4fd3bd4e4ac09f824b1d177a6539e4cd6f14141
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4N0U4OjFGNkE6MjU5NTNGOjMyNDg2Qzo2QUZCRTUyRiIsInZpc2l0b3JfaWQiOiI2NTkyNTEyMzkxNTM4MDA5MzkxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac117c856d6e68b3dc7bf20c3d9396d97a304c5dc72fef24f2d4c15597c4531287
hovercard-subject-tagissue:2150992308
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/javascript-tutorial/ru.javascript.info/1934/issue_layout
twitter:imagehttps://opengraph.githubassets.com/4eefd99a4f9e14215ce8197116bc127e0955699196f64132377fa53e330272ff/javascript-tutorial/ru.javascript.info/issues/1934
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/4eefd99a4f9e14215ce8197116bc127e0955699196f64132377fa53e330272ff/javascript-tutorial/ru.javascript.info/issues/1934
og:image:altОписание После прочтения главы учебника про Генераторы мне стала интересна эта тема я и решил уделить чуть больше внимания, чем на остальные темы. И в конечном итоге я нашел одну особенность, котор...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameSmail000
hostnamegithub.com
expected-hostnamegithub.com
None744d4381b1c4dbd6d8736c7d7e5bbe7dc11217584e457a3555020c631764e8ec
turbo-cache-controlno-preview
go-importgithub.com/javascript-tutorial/ru.javascript.info git https://github.com/javascript-tutorial/ru.javascript.info.git
octolytics-dimension-user_id49552305
octolytics-dimension-user_loginjavascript-tutorial
octolytics-dimension-repository_id160851084
octolytics-dimension-repository_nwojavascript-tutorial/ru.javascript.info
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id160851084
octolytics-dimension-repository_network_root_nwojavascript-tutorial/ru.javascript.info
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasedf859c48a4c8b4c0009c19bb4e82101aacb4b998
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/javascript-tutorial/ru.javascript.info/issues/1934#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fjavascript-tutorial%2Fru.javascript.info%2Fissues%2F1934
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fjavascript-tutorial%2Fru.javascript.info%2Fissues%2F1934
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=javascript-tutorial%2Fru.javascript.info
Reloadhttps://github.com/javascript-tutorial/ru.javascript.info/issues/1934
Reloadhttps://github.com/javascript-tutorial/ru.javascript.info/issues/1934
Reloadhttps://github.com/javascript-tutorial/ru.javascript.info/issues/1934
javascript-tutorialhttps://github.com/javascript-tutorial
ru.javascript.infohttps://github.com/javascript-tutorial/ru.javascript.info
Codehttps://github.com/javascript-tutorial/ru.javascript.info
Issues32 (32)https://github.com/javascript-tutorial/ru.javascript.info/issues
Pull requests106 (106)https://github.com/javascript-tutorial/ru.javascript.info/pulls
Actionshttps://github.com/javascript-tutorial/ru.javascript.info/actions
Projectshttps://github.com/javascript-tutorial/ru.javascript.info/projects
Security and qualityhttps://github.com/javascript-tutorial/ru.javascript.info/security
Insightshttps://github.com/javascript-tutorial/ru.javascript.info/pulse
https://github.com/javascript-tutorial/ru.javascript.info
New issuehttps://github.com/login?return_to=https://github.com/javascript-tutorial/ru.javascript.info/issues/1934
New issuehttps://github.com/login?return_to=https://github.com/javascript-tutorial/ru.javascript.info/issues/1934
[Предложение: учебник]: yield* тоже работает в две стороныhttps://github.com/javascript-tutorial/ru.javascript.info/issues/1934#top
suggestion: tutorialhttps://github.com/javascript-tutorial/ru.javascript.info/issues?q=state%3Aopen%20label%3A%22suggestion%3A%20tutorial%22
https://github.com/Smail000
Smail000https://github.com/Smail000
on Feb 23, 2024https://github.com/javascript-tutorial/ru.javascript.info/issues/1934#issue-2150992308
Генераторыhttps://learn.javascript.ru/generators
Smail000https://github.com/Smail000
suggestion: tutorialhttps://github.com/javascript-tutorial/ru.javascript.info/issues?q=state%3Aopen%20label%3A%22suggestion%3A%20tutorial%22
on Feb 23, 2024https://github.com/javascript-tutorial/ru.javascript.info/issues/1934#event-11903112198
Sign up for freehttps://github.com/signup?return_to=https://github.com/javascript-tutorial/ru.javascript.info/issues/1934
Sign in to commenthttps://github.com/login?return_to=https://github.com/javascript-tutorial/ru.javascript.info/issues/1934
suggestion: tutorialhttps://github.com/javascript-tutorial/ru.javascript.info/issues?q=state%3Aopen%20label%3A%22suggestion%3A%20tutorial%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.