- Notifications
You must be signed in to change notification settings - Fork179
Function object, NFE#198
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
tarasyyyk merged 22 commits intojavascript-tutorial:masterfromMykolaSopiha:function-objectSep 13, 2021
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
22 commits Select commitHold shift + click to select a range
8a5ab06
function-object
MykolaSopihab4c9f9f
function-object
MykolaSopiha7e792a6
function-object
MykolaSopiha836c408
function-object
MykolaSopihaf84c353
function-object
MykolaSopiha76ba9df
function-object
MykolaSopiha8ea92d8
function-object
MykolaSopiha848a163
function-object
MykolaSopihae5d98d8
Update 1-js/06-advanced-functions/06-function-object/2-counter-inc-de…
MykolaSopihad53d5f9
Update 1-js/06-advanced-functions/06-function-object/5-sum-many-brack…
MykolaSopihafb61ef8
Update 1-js/06-advanced-functions/06-function-object/5-sum-many-brack…
MykolaSopiha8c438ff
Update 1-js/06-advanced-functions/06-function-object/5-sum-many-brack…
MykolaSopihafa8ae01
Update 1-js/06-advanced-functions/06-function-object/article.md
MykolaSopihab9602bd
Update 1-js/06-advanced-functions/06-function-object/article.md
MykolaSopihabf2f942
Update 1-js/06-advanced-functions/06-function-object/5-sum-many-brack…
MykolaSopiha3f73e08
Update 1-js/06-advanced-functions/06-function-object/article.md
MykolaSopiha0d08ac0
function-object
MykolaSopiha8f2a963
Merge branch 'function-object' of github.com:MykolaSopiha/uk.javascri…
MykolaSopiha177060e
function-object
MykolaSopiha2231004
function-object
MykolaSopiha9e1033e
Update 1-js/06-advanced-functions/06-function-object/5-sum-many-brack…
tarasyyykbde190b
Update 1-js/06-advanced-functions/06-function-object/5-sum-many-brack…
tarasyyykFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
В рішенні використовується `count`у локальній змінній, але методи додавання записуються прямо в`counter`.Вони поділяють таке ж зовнішнє лексичне середовище, а також можуть отримати доступ до поточного `count`. |
14 changes: 7 additions & 7 deletions1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
24 changes: 12 additions & 12 deletions1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
1.Загалом, для того щоб все працювало *хоч як-небудь*,результат`sum`повинен бути функцією. | ||
2.Ця функція повинна зберігати в пам’яті поточне значення між викликами. | ||
3.Згідно з завданням, функція повинна стати числом, коли використовується в`==`.Функції -- це об’єкти, тому перетворення відбувається як описано в розділі<info:object-toprimitive>,і ми можемо надати власний метод, який повертає номер. | ||
Тепер код: | ||
```js demo run | ||
function sum(a) { | ||
@@ -28,28 +28,28 @@ alert( sum(6)(-1)(-2)(-3) ); // 0 | ||
alert( sum(0)(1)(2)(3)(4)(5) ); // 15 | ||
``` | ||
Зверніть увагу, що функція `sum`фактично працює лише раз. Вона повертає функцію `f`. | ||
Потім, на кожному наступному виклику, `f`додає свій параметр до суми`currentSum`,і повертає себе. | ||
tarasyyyk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
**В останньому рядку`f` немає ніякої рекурсії.** | ||
Ось як рекурсія виглядає: | ||
```js | ||
function f(b) { | ||
currentSum += b; | ||
return f(); // <--рекурсивний виклик | ||
} | ||
``` | ||
А в нашому випадку ми просто повертаємо цю функцію, не викликаючи її: | ||
```js | ||
function f(b) { | ||
currentSum += b; | ||
return f; // <--не викликає себе, повертає себе | ||
} | ||
``` | ||
Ця функція`f`буде використовуватися в наступному виклику і знову поверне себе стільки разів, скільки буде потрібно. Потім, при використанні функції як числа або рядка--метод `toString`поверне`currentSum`.Тут ми також можемо використовувати`Symbol.toPrimitive`або `valueOf`для конверсії. |
6 changes: 3 additions & 3 deletions1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -2,9 +2,9 @@ importance: 2 | ||||||
--- | ||||||
#Сума з довільною кількістю дужок | ||||||
Напишіть функцію `sum`, яка б працювала так: | ||||||
```js | ||||||
sum(1)(2) == 3; // 1 + 2 | ||||||
@@ -14,4 +14,4 @@ sum(6)(-1)(-2)(-3) == 0 | ||||||
sum(0)(1)(2)(3)(4)(5) == 15 | ||||||
``` | ||||||
P.S.Підказка: вам може знадобитися налаштувати кастомний об'єкт, щоб конвертувати примітиви для вашої функції. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
|
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.