forked from chuanxshi/javascript-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallbacks-and-scope.html
More file actions
44 lines (40 loc) · 853 Bytes
/
callbacks-and-scope.html
File metadata and controls
44 lines (40 loc) · 853 Bytes
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
<!doctype html>
<html lang="en">
<head>
<title>JavaScript Patterns</title>
<meta charset="utf-8">
</head>
<body>
<script>
var myapp = {};
myapp.color = "green";
myapp.paint = function (node) {
node.style.color = this.color;
};
var findNodes = function (callback) {
// ...
if (typeof callback === "function") {
callback(found);
}
// ...
};
var findNodes = function (callback, callback_obj) {
// ...
if (typeof callback === "function") {
callback.call(callback_obj, found);
}
// ...
};
var findNodes = function (callback, callback_obj) {
if (typeof callback === "string") {
callback = callback_obj[callback];
}
// ...
if (typeof callback === "function") {
callback.call(callback_obj, found);
}
// ...
};
</script>
</body>
</html>