-
Notifications
You must be signed in to change notification settings - Fork 0
/
badideas.html
106 lines (84 loc) · 2.24 KB
/
badideas.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Bad Ideas in JavaScript</title>
</head>
<body>
<h1>Bad Ideas in JavaScript</h1>
<p>Things that do not work, and things that actually do.</p>
<h3>Idea 1</h3>
<div id="foo">(Results will appear here, assuming everything compiles)</div>
<h3>Idea 2</h3>
<div id="bar">(Results will appear here, assuming everything compiles)</div>
<h3>Idea 3</h3>
<div id="baz">(Results will appear here, assuming everything compiles)</div>
<h3>Idea 4</h3>
<div id="hello">(Results will appear here, assuming everything compiles)</div>
<h3>Idea 5</h3>
<div id="world">(Results will appear here, assuming everything compiles)</div>
<h3>Idea 6</h3>
<div id="r6">(Results will appear here, assuming everything compiles)</div>
<script type="text/javascript">
(function(){
// One
var foo = function(){
this.dog = function(){ return 'bark!'; };
return this; // this lets Idea 5 work, later.
}
var results = '(failed)';
try {
results = foo.dog();
} catch (e) {
results = 'That didn\'t work! <br>'+e;
}
(document.getElementById('foo')).innerHTML = results;
// Two
var bar = function(){
return {
dog: function() {return 'woof!';}
};
}
var results2 = '(failed)';
try {
results2 = bar.dog();
} catch (e) {
results2 = 'That didn\'t work! <br>'+e;
}
(document.getElementById('bar')).innerHTML = results2;
// Three
var results3 = '(failed)';
try {
results3 = (new foo()).dog();
} catch (e) {
results3 = 'That didn\'t work! <br>'+e;
}
(document.getElementById('baz')).innerHTML = results3;
// four
var results4 = '(failed)';
try {
results4 = (new bar()).dog();
} catch (e) {
results4 = 'That didn\'t work! <br>'+e;
}
(document.getElementById('hello')).innerHTML = results4;
// Five
var results5 = '(failed)';
try {
results5 = foo().dog();
} catch (e) {
results5 = 'That didn\'t work! <br>'+e;
}
(document.getElementById('world')).innerHTML = results5;
// Six
var results6 = '(failed)';
try {
results6 = bar().dog();
} catch (e) {
results6 = 'That didn\'t work! <br>'+e;
}
(document.getElementById('r6')).innerHTML = results6;
})();
</script>
</body>
</html>