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: node_101.md
+34-33
Original file line number
Diff line number
Diff line change
@@ -2,85 +2,87 @@
2
2
3
3
A computer program can run in many host environments.
4
4
5
-
Programs run on desktops, tablets, small devices, smart devices.
5
+
Programs run on desktops, smart phones, and tiny devices everywhere.
6
6
7
7
Some programs run across various operating systems; this is useful.
8
8
9
-
This is possible because the language of your program has interpretters and compilers that work in a particular host environment.
9
+
This is possible because the language of your program has interpretters and compilers that work in a particular host environment, usually on top of an operating system.
10
10
11
-
It's very environmental.
11
+
It's all very environmental, programming; behind the curtain, hacks upon hacks to make programs and environments compatible.
12
12
13
-
Javascript programs run inside every browser tab.
13
+
Javascript programs run inside every web page, inside every browser, on any device which has one.
14
14
15
15
On billions of devices, across all operating systems.
16
16
17
17
Node.js created an environment for running javascript outside of the browser as well.
18
18
19
-
This allowed for many new kinds of applications to be written in Javascript, which previously worked only in the browser.
19
+
This allowed for many new kinds of applications to be written in Javascript, applications which use systems and resources not available inside the safe, sandboxed environment of the web browser.
20
20
21
21
Node.js was a very clever hack, and has become a invaluable tool for web developers.
22
22
23
-
Node.js performs very well for what it was intended. Node.js was intended for writing web server applications, the back-end.
23
+
Node.js performs very well for what it was intended, which is writing web server applications, aka the back-end.
24
24
25
-
Node.js also performs well enough for many things it was never intended, because it made writing myriad various programs much less painful.
25
+
Node.js also performs well enough for many things it was never intended, because it made writing myriad various programs much less brutal.
26
26
27
-
This is entirely due to a large commnity of open source programmers, slowly chiseling at good forms, styles, and practices.
27
+
This is entirely due to a large commnity of open source programmers, chiseling away at complicated system designs.
28
28
29
-
Many of these would be codified into Node.js, and from there influence code writing for front-end apps.
29
+
These designs and practices became the conventions of Node.js and its modules; and it influenced code writing for front-end apps.
30
30
31
-
And there is no doubt Node.js has set the bar for community backed open source development, as much as it sets a bar for high performance web apps.
31
+
Node.js has set the bar for community backed open source project development, as much as it sets a bar for high performance web apps.
32
32
33
33
Perhaps best of all, Node.js allows the intrepid hacker to create full stack, web applications with a single language: javascript.
34
34
35
35
# Events
36
36
37
-
EVENTS are an important concept for the javascript and Node.js programmer, as well as designers of interfaces, or machines with sesnors.
37
+
EVENTS are an important concept for the javascript and Node.js programmer, as well as designers of interfaces, or systems with sesnors.
38
38
39
-
What is an event? Unlike many programming concepts, an event is exactly what you should expect.
39
+
What is an event? Unlike some programming concepts, an event here is exactly what you should expect.
40
40
41
41
An event is when something happens.
42
42
43
43
Javascript is the language of the browser, and that includes user interactions--events.
44
44
45
45
Therefor Javascript has always been event oriented.
46
46
47
-
Node.js took this evented straight to the core, creating an event driven architecture, which turned out to be a brilliant idea.
48
-
49
47
Almost everything is an event.
50
48
51
-
A click, a key press, a scroll motion, are events.
49
+
A click, a key press, a swipe motion, are events.
52
50
53
51
A connection, an update, an interval, are events.
54
52
55
53
Some events can be broken down into several events.
56
54
57
-
A button is pressed, is held, is released.
55
+
A button is pressed, is held, and then is released.
56
+
57
+
A conncection is opened, is upgraded, and then is closed.
58
58
59
-
A conncection is opened, is upgraded, is closed.
59
+
You may have different directives for each event, or one for all.
60
60
61
-
Many programmers failed to realize this nature of javasctipt, because they wrote most of their code in another language, which did not emphesize events.
61
+
Many programmers failed to realize this nature of javasctipt, because they write most of their code in another "back end" language, which did not emphesize events.
62
62
63
-
The result are many confusing paradigms for wriring javasctipt programs, such as Model-View-Controller, or MVC.
63
+
The result are several confusing paradigms for wriring javasctipt programs, such as Model-View-Controller, or MVC.
64
64
65
65
With Node.js, events are fundamental, the basis for all higher order constructs, most importantly STREAMS.
66
66
67
-
A stream takes a pattern of events, and creates a flow out them.
67
+
A stream takes a pattern of events, and creates a flow out them, and allows you to program in the context of that flow.
68
68
69
-
But how do you write a program that anticipates various events, and then does something with the potentially unknown consequences of these events, such as an error, or the receipt of arbitrary data?
69
+
More on streams in another discussion.
70
+
71
+
So, how do you write a program that anticipates various events, and then does something with the potentially unknown consequences of these events, such as an error, or the receipt of arbitrary data?
70
72
71
73
There is only one answer.
72
74
73
-
You must write functions that listen for verious, specified events, and you must write functions that handle the result of the events, if and when they occur.
75
+
You must write functions that listen for various events, and you must write functions that handle the result of these events, if and when they occur.
74
76
75
77
The first kind is a "listener".
76
78
77
79
The second is a CALLBACK.
78
80
79
81
# Callbacks
80
82
81
-
A CALLBACK is simply a function, no different than any other function, which is called upon an event.
83
+
A CALLBACK is simply a function--no different than any other function--which is called upon an event.
82
84
83
-
Most confusion about calbacks stems from confusion, or laziness, about javascipt functional syntax.
85
+
Most confusion about javascript callbacks stems from confusion and lazioness about javascipt functional syntax.
To the uninitiated, this may look like a pinata of inscruotable syntax.
94
+
To the uninitiated, this may look like a pinata of inscruotable syntax; and hlaf of it comprises the callback.
93
95
94
-
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
+
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.
95
97
96
-
Another way looks like this:
98
+
Look at another way to write the same thing:
97
99
```js
100
+
// I literally cut and copied everything after the = from the previous example
98
101
varcallback_Function=function(data){
99
102
console.log(data)
100
103
}
101
104
102
105
event.on('update', callback_Function)
103
106
```
104
107
105
-
Now you can see that the callback is a generic function, and event.on is a function being called() with two arguments, one of them a function.
106
-
107
-
When an event fires that is an 'update', call the supplied function, in this case 'callback_Function'.
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.
108
109
109
-
It is very common in javascript to supply a function as an argument, like in real life you might give directions "in the event" something occurs.
110
+
When an 'update' event happens, call the supplied function, in this case 'callback_Function', which was reference above.
110
111
111
-
Node.js is build around events. This is because there is often some time between the initiation of a sequence, and it the events which are produced.
112
+
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.
112
113
113
-
Direct your program to open a file, and when the file is open, do something.
114
+
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.
0 commit comments