Skip to content

Commit 7b05022

Browse files
committed
Update node_101.md
1 parent 35954ad commit 7b05022

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

node_101.md

+33-5
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@ event.on('update', function(data){
9191
console.log(data)
9292
})
9393
```
94-
To the uninitiated, this may look like a pinata of inscruotable syntax; and hlaf of it comprises the callback.
94+
To the uninitiated, this may look like a pinata of inscruotable syntax.
9595

96-
There, a function is being called, which takes two arguments. One argument is the string, 'update'. The next argument is a function. This is confusing because that function is written out within the parenthesis of the function being called.
96+
One reason is because that code has nested syntax, which is totally legal.
9797

98-
Look at another way to write the same thing:
98+
Half of that code is a callback.
99+
100+
On the outside, a function is being called, which takes two arguments between its parenthesis. One argument is a string, 'update'. The next argument is a function, written out. This is confusing because that function is written out within the parenthesis of the function being called.
101+
102+
However, look at another way to write the same thing:
99103
```js
100104
// I literally copied everything after the = from the previous example
101105
var callback_Function = function(data){
@@ -105,16 +109,40 @@ var callback_Function = function(data){
105109
event.on('update', callback_Function)
106110
```
107111

108-
Here, you can see that the callback is a basic function, and event.on is a function being called with two arguments, one of them a function.
112+
Here, you can see that the callback is a basic function, and event.on is a function being called with two arguments, one of them the function referenced aboove.
109113

110-
When an 'update' event happens, call the supplied function, in this case 'callback_Function', which was reference above.
114+
When an 'update' event happens, call the supplied function.
111115

112116
It is very common in javascript to supply a function as an argument to another function, like in real life you might give directions "in the event" something occurs.
113117

118+
As with all writing, code can get sloppy; we often forgetting, or ignoring, the fact that other humans will actually try to read and understand this.
119+
114120
Node.js is built on top of events. This is because there is often some time between the initiation of a sequence, and it the events which are produced; for instance when you fetch data from a far away server, and wait for the response.
115121

116122
so much for events and callbacks.
117123

124+
# psyche!
125+
126+
Events and callbacks are a paradigm for handling asyncronous behaviours.
127+
128+
One asyncronous behaviour is your very own: you write the code before it runs.
129+
130+
The other async behaviour occurs naturally as a result of time and space.
131+
132+
Asyncronous is the word.
133+
134+
This guide did nothing say of how to deal with asyncronous behaviours.
135+
136+
Async behaviours did not come natural to most early programmers of other languages, but that doesn't have to be the case with you.
137+
138+
There are many styles to try writing javascript, to wend your way about intersecting streams of data and outer userspace.
139+
140+
Thread the needle.
141+
142+
or, try the [sweet bun style](https://www.youtube.com/watch?v=HtBebT-rKeM&list=PLYgHYEWMPzcrzcbGGqJyTKE9FK6DLTCiw)
143+
144+
145+
118146

119147

120148

0 commit comments

Comments
 (0)