Skip to content

Commit 480d8d9

Browse files
committed
Update node_101.md
1 parent 57201d6 commit 480d8d9

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

node_101.md

+34-33
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,87 @@
22

33
A computer program can run in many host environments.
44

5-
Programs run on desktops, tablets, small devices, smart devices.
5+
Programs run on desktops, smart phones, and tiny devices everywhere.
66

77
Some programs run across various operating systems; this is useful.
88

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.
1010

11-
It's very environmental.
11+
It's all very environmental, programming; behind the curtain, hacks upon hacks to make programs and environments compatible.
1212

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.
1414

1515
On billions of devices, across all operating systems.
1616

1717
Node.js created an environment for running javascript outside of the browser as well.
1818

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.
2020

2121
Node.js was a very clever hack, and has become a invaluable tool for web developers.
2222

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.
2424

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.
2626

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.
2828

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.
3030

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.
3232

3333
Perhaps best of all, Node.js allows the intrepid hacker to create full stack, web applications with a single language: javascript.
3434

3535
# Events
3636

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.
3838

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.
4040

4141
An event is when something happens.
4242

4343
Javascript is the language of the browser, and that includes user interactions--events.
4444

4545
Therefor Javascript has always been event oriented.
4646

47-
Node.js took this evented straight to the core, creating an event driven architecture, which turned out to be a brilliant idea.
48-
4947
Almost everything is an event.
5048

51-
A click, a key press, a scroll motion, are events.
49+
A click, a key press, a swipe motion, are events.
5250

5351
A connection, an update, an interval, are events.
5452

5553
Some events can be broken down into several events.
5654

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.
5858

59-
A conncection is opened, is upgraded, is closed.
59+
You may have different directives for each event, or one for all.
6060

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.
6262

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.
6464

6565
With Node.js, events are fundamental, the basis for all higher order constructs, most importantly STREAMS.
6666

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.
6868

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?
7072

7173
There is only one answer.
7274

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.
7476

7577
The first kind is a "listener".
7678

7779
The second is a CALLBACK.
7880

7981
# Callbacks
8082

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.
8284

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.
8486

8587
Consider the following:
8688

@@ -89,28 +91,27 @@ event.on('update', function(data){
8991
console.log(data)
9092
})
9193
```
92-
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.
9395

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.
9597

96-
Another way looks like this:
98+
Look at another way to write the same thing:
9799
```js
100+
// I literally cut and copied everything after the = from the previous example
98101
var callback_Function = function(data){
99102
console.log(data)
100103
}
101104

102105
event.on('update', callback_Function)
103106
```
104107

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.
108109

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.
110111

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.
112113

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.
114115

115116
so much for events and callbacks.
116117

0 commit comments

Comments
 (0)