You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: concepts/callbacks/about.md
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,9 @@ It is also useful to use _callback functions_ because they may reference variabl
15
15
_Event handlers_ are a common use-case for callbacks in JavaScript. Browser events like `'onload'` or `'onclick'` are signals which can trigger functions to be invoked. A DOM [[Document Object Model](mdn-dom) object's `addEventListener` method registers a callback function to be invoked when it "hears" that an event has occurred.
16
16
17
17
```javascript
18
-
document.addEventListener('onload', () =>alert('The webpage has now been loaded'))
Copy file name to clipboardExpand all lines: exercises/concept/fruit-picker/.docs/instructions.md
+10-6Lines changed: 10 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -4,20 +4,20 @@ You are creating a new online portal for your patrons to order their fruit fresh
4
4
5
5
## 1. Create a callback to be called when the order is successful
6
6
7
-
Write a callback function called `onSuccess` to be called when the order is successful. It should invoke the imported `notify` function passing a success message to it.
7
+
Write a callback function called `onSuccess` to be called when the order is successful. It should invoke the imported `notify` function passing a success message to it.
8
8
9
9
```javascript
10
10
onSuccess();
11
-
// => `nofify` called with `{ message: 'SUCCESS' }`
11
+
// => `notify` called with `{ message: 'SUCCESS' }`
12
12
```
13
13
14
14
## 2. Create a callback to be called when the order fails with an error
15
15
16
-
Write a callback function called `onError` to be called when the order encounters an error. It should invoke the imported `notify` function passing an error message to it.
16
+
Write a callback function called `onError` to be called when the order encounters an error. It should invoke the imported `notify` function passing an error message to it.
17
17
18
18
```javascript
19
19
onError();
20
-
// => `nofify` called with `{ message: 'ERROR' }`
20
+
// => `notify` called with `{ message: 'ERROR' }`
21
21
```
22
22
23
23
## 3. Create a wrapper to wrap the external api function
// => `order` was called with the query and the callbacks
39
43
```
40
44
@@ -43,6 +47,6 @@ orderFromGrocer({variety: 'pear', quantity: 12}, exampleSuccessCallback, example
43
47
You find that you are calling this function from many different places with the same functions. Seeing an opportunity to refactor your code, you want to create a function where you can supply the variety and quantity to order as arguments.
0 commit comments