-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter04.html
More file actions
61 lines (55 loc) · 1.82 KB
/
Copy pathChapter04.html
File metadata and controls
61 lines (55 loc) · 1.82 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<script src="jquery-1.8.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
function lastElement(array) {
if (array.length > 0) {
return array[array.length - 1];
} else {
throw "Cannot take the last element of an empty array.";
}
}
function lastElementPlusTen(array) {
return lastElement(array) * 10;
}
//$(function () {
// try {
// alert(lastElementPlusTen([]));
// } catch (error) {
// alert("Something went wrong:" + error);
// }
//});
var currentThing = null;
function processThing(thing) {
var prevThing = currentThing;
currentThing = thing;
try {
/*做复杂的处理*/
} finally {
currentThing = prevThing;
}
}
function between(string, start, end) {
var startAt = string.indexOf(start) + start.length;
var endAt = string.indexOf(end, startAt);
return string.slice(startAt, endAt);
}
function testBetween() {
function assert(name, x) {
if (!x) {
throw "Assertion failed: " + name;
}
}
assert("identical delimiters", between("a|b|c", "|", "|") == "b");
assert("whole string", between("[[n]]", "[[", "]]") == "n");
assert("reversed", between("]x[", "[", "]") == (undefined | ""));
assert("missing end", between("-->d", "-->", "<--") == (undefined | ""));
}
</script>
</head>
<body>
</body>
</html>