blob: b672a4360f80bcdd5ff585f4e826ee8f21333e09 (
plain)
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
|
<!-- Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ -->
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Bound event listeners test page</title>
</head>
<body>
<button id="initialSetup">initialSetup</button>
<button id="clicker">clicker</button>
<button id="handleEventClick">handleEventClick</button>
<button id="boundHandleEventClick">boundHandleEventClick</button>
<script type="text/javascript">
window.addEventListener("load", function onload() {
window.removeEventListener("load", onload);
function initialSetup(event) {
var button = document.getElementById("initialSetup");
button.removeEventListener("click", initialSetup);
debugger;
}
function clicker(event) {
window.foobar = "clicker";
}
function handleEventClick() {
var button = document.getElementById("handleEventClick");
// Create a long prototype chain to test for weird edge cases.
button.addEventListener("click", Object.create(Object.create(this)));
}
handleEventClick.prototype.handleEvent = function() {
window.foobar = "handleEventClick";
};
function boundHandleEventClick() {
var button = document.getElementById("boundHandleEventClick");
this.handleEvent = this.handleEvent.bind(this);
button.addEventListener("click", this);
}
boundHandleEventClick.prototype.handleEvent = function() {
window.foobar = "boundHandleEventClick";
};
var button = document.getElementById("clicker");
// Bind more than once to test for weird edge cases.
var boundClicker = clicker.bind(this).bind(this).bind(this);
button.addEventListener("click", boundClicker);
new handleEventClick();
new boundHandleEventClick();
var initButton = document.getElementById("initialSetup");
initButton.addEventListener("click", initialSetup);
});
</script>
</body>
</html>
|