forked from wchaowu/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4 - More on adapting an email API.js
More file actions
33 lines (30 loc) · 1.13 KB
/
Copy path4 - More on adapting an email API.js
File metadata and controls
33 lines (30 loc) · 1.13 KB
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
// DED.util.substitute()函数的使用例子
var substitutionObject = {
name: "world",
place: "Google"
};
var text = 'Hello {name}, welcome to {place}';
var replacedText = DED.util.substitute(text, substitutionObject);
console.log(replacedText);
// produces "Hello world, welcome to Google"
// 原来fooMail的API中getMail的使用方式
fooMail.getMail(function(text) {
$('message-pane').innerHTML = text;
});
// 为dedMail添加适配器,使其调用方式和fooMail的一样
var dedMailtoFooMailAdapter = {};
dedMailtoFooMailAdapter.getMail = function(id, callback) {
dedMail.getMail(id, function(resp) {
var resp = eval('('+resp+')');
var details = '<p><strong>From:</strong> {from}<br>';
details += '<strong>Sent:</strong> {date}</p>';
details += '<p><strong>Message:</strong><br>';
details += '{message}</p>';
callback(DED.util.substitute(details, resp));
});
};
// Other methods needed to adapt dedMail to the fooMail interface.
//todo
// Assign the adapter to the fooMail variable.
// 把适配器赋给fooMail变量,这样就不用修改客户端的其他代码了
fooMail = dedMailtoFooMailAdapter;