-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromise-polyfill.js
38 lines (34 loc) · 1 KB
/
promise-polyfill.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
const user = {
get: function (id, name) {
console.log('Getting user...');
setTimeout(() => {
const user = { id: id, gitHubUsername: name };
if (id === 0) {
console.log("Executing captured success callback.");
this.failureCb({message: "Something went wrong."});
}
else {
console.log("Executing captured success callback.");
this.successCb(user);
}
}, 2000);
return this;
},
success: function (cb) {
console.log('Capturing success callback');
this.successCb = cb;
return this;
},
failure: function (cb) {
console.log('Capturing failure callback');
this.failureCb = cb;
return this;
},
successCb: null,
failureCb: null,
};
user.get(12, 'whatever')
.success(function(user){
console.log("success!", user);
})
.failure((error) => console.log('failure!', error));