-
-
Notifications
You must be signed in to change notification settings - Fork 627
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
Update Fruit Picker -- remove conceptual leaps #1725
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1579b22
update WIP
neenjaw fc95fb6
iteration
neenjaw 16fc3fa
update test file
neenjaw f6e330a
update exemplar and stubify exercise
neenjaw 90f0170
update some of the docs to reduce scope
neenjaw 92138ec
More clean up:
neenjaw ef58611
configlet feedback
neenjaw 3d7b81a
update import in test file
neenjaw fe60906
`npx prettier -w`
neenjaw 9538bc5
remove ts-check explanation
neenjaw ea513fc
migrate to one describe per task
neenjaw ff23036
re-introduce arrow-functions as taught-concept
neenjaw 7485701
update function naming inexample
neenjaw dd155a5
updates to about.md
neenjaw 06ae3bc
npx prettier
neenjaw 0fe22a5
Re-add arrow functions for Translation Service
junedev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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,35 +1,29 @@ | ||
# Introduction | ||
|
||
Callbacks are functions that are passed as arguments to another function. This is often done to control the order of execution in an asynchronous context. Writing a callback function is no different from writing a function, but the callback function's arguments must match the signature required by the calling function. | ||
## Callback functions | ||
|
||
Callback functions are functions passed as arguments. This programming pattern creates a sequence of function calls in both synchronous and asynchronous programming. Writing a callback function is no different from writing a function; however, the callback function must match the signature defined by the calling function. | ||
|
||
```javascript | ||
const squareLength = 5; | ||
const sideLength = 5; | ||
|
||
// Caller function takes a callback function | ||
function applyToSquare(callback) { | ||
return callback(squareLength); | ||
function applySideLength(callback) { | ||
return callback(sideLength); | ||
} | ||
|
||
// Callback must expect the possible argument from the calling function | ||
function areaOfSquare(number) { | ||
return number * number; | ||
function squareArea(side) { | ||
return side * side; | ||
} | ||
|
||
applyToSquare(areaOfSquare); // => 25 | ||
applySideLength(areaOfSquare); // => 25 | ||
``` | ||
|
||
You may also write callbacks as a function expression: | ||
|
||
```javascript | ||
applyToSquare(function squarePerimeter(side) { | ||
applySideLength(function squarePerimeterLength(side) { | ||
return side * 4; | ||
}); | ||
``` | ||
|
||
Or an anonymous inline arrow function expression: | ||
|
||
```javascript | ||
applyToSquare((side) => side * 4); | ||
``` | ||
|
||
// The argument "(side) => side \* 4" is the callback |
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about having a the category for all the forEach, map, filter, etc methods in JavaScript? I often notice beginners don't understand that the argument is a callback function that will be applied to the elements. I think it would be good to include it as a first example category in the list. However, I am not sure how to name the category ... maybe "Iteration Callbacks" ... idk ... maybe you have a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't those array methods taught in other concept exercises? Shouldn't it be those exercises' responsibility to build on prior knowledge and point out that those array functions are callbacks in disguise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We (DJ and me) have the guideline that about.md files are not bound by the syllabus progression because they are used for later reference. So if something is a good fit to explain a concept, we would include it in the about.md no matter where it would show up in the concept tree (if at all). My feeling is that the current example categories have some "overweight" on the complex side. That is why I though a simpler category would balance it out. Not a blocker though. Feel free to click resolve if you prefer it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Detail added in dd155a5, sub-titled as "Callbacks in disguise"