-
Notifications
You must be signed in to change notification settings - Fork 0
/
overrides.html
103 lines (88 loc) · 2.77 KB
/
overrides.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
<!doctype html>
<html lang="en" data-theme="dark">
<head>
<meta charset="utf-8">
<title>Overrides</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="icon.png">
<link rel="stylesheet" href="css/pico.css">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<main class="container">
<section>
<h1>Native overrides</h1>
<p>Overriding of the native functions and properties can be quite helpful in some cases</p>
<article id="form-article">
<h2>Fill out the form to see the content</h2>
<br>
<form id="form">
<div class="grid">
<input type="text" name="firstname" placeholder="First name" aria-label="First name" required>
<input type="email" name="email" placeholder="Email address" aria-label="Email address" required>
<button id="submit" type="submit">Subscribe</button>
</div>
</form>
</article>
<article id="content" style="display: none">
<h2>Override native functions/methods</h2>
<p>
As easy as assigning a value, like
</p>
<code>
<u>alert</u> = function() { <b>debugger</b>; };
</code>
<h2>Override native properties</h2>
<p>
In most case it's same as in property breakpoints, but sometimes you'll need properties on prototypes
</p>
<code style="width: 100%">
<s>Object</s>.<u>defineProperty</u>(<s>HTMLInputElement</s>.<s>prototype</s>, <i>'value'</i>, {
<br>
  <u>get</u>() { <b>debugger</b>; },
<br>
  <u>set</u>(v) { <b>debugger</b>; },
<br>
});
<br>
<s>input</s>.value = <i>'hello'</i>; <em>// debugger will stop here</em>
</code>
<h2>Trick of the day:</h2>
<code><s>console</s>.<u>trace()</u>;</code>
and
<code><b>new</b> <s>Error</s>().stack</code>
to know the call stack
</article>
<div class="grid">
<a href="property-breakpoints.html">
<button class="secondary">Back</button>
</a>
<div></div>
<a href="credits.html">
<button>Finish</button>
</a>
</div>
</section>
</main>
<script>
const submitButton = document.getElementById('submit');
const formArticle = document.getElementById('form-article');
const form = document.getElementById('form');
const content = document.getElementById('content');
submitButton.onclick = e => {
if (!form.reportValidity()) {
console.log('form invalid');
return;
}
formArticle.style.display = 'none';
content.style.display = '';
e.preventDefault();
}
</script>
<footer class="container">
WebCore 2021
</footer>
<script src="js/lib/jquery3.6.js"></script>
<script src="js/lib/react.js"></script>
</body>
</html>