-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapter2.js
45 lines (34 loc) · 933 Bytes
/
chapter2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const co = require('./common');
let username = 'AwesomeUser';
function hi(name) {
return 'hi, ' + name;
}
let greeting = hi;
co.say(greeting(username));
//=========================================
function ajaxCall(callback) {
co.say('Performing request...');
return callback('json');
}
function getServerStaff(callback) {
return ajaxCall(function (json) {
return callback(json);
})
}
getServerStaff((json) => co.say(json));
// enlightened
getServerStaff = ajaxCall;
getServerStaff((json) => co.say(json));
//=========================================
function httpGet(path, callback) {
co.say('Http get. Path: ' + path);
return callback('json');
}
function renderPost(json) {
co.say('Rendering post...');
co.say('Post created: ' + json);
}
httpGet('/post/2', (json) => renderPost(json));
// enlightened
httpGet('/post/2', renderPost);
//=========================================