-
Notifications
You must be signed in to change notification settings - Fork 0
/
short.html
218 lines (202 loc) · 5.26 KB
/
short.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>JavaScript im Jahr 2011 – Kurzversion</title>
<script src="slides.js"></script>
<style>
.scy h3 {
font-size: 48px;
}
.scy pre {
margin-top: 10px;
margin-bottom: 10px;
}
</style>
</head>
<body class="scy" style="display: none;">
<section class="slides layout-regular template-default">
<article>
<h1>JavaScript im Jahr 2011</h1>
<p>Tim „Scytale“ Weber <<a href="http://scytale.name/">http://scytale.name/</a>></p>
<p>12. September 2011</p>
<p>9. Webmontag.talk des Webmontag MRN, Musikpark Mannheim</p>
<p>Fragen/Feedback: <strong><a href="https://twitter.com/Scytale">@Scytale</a></strong></p>
</article>
<article>
<h3>Ich</h3>
<ul>
<li>Tim <strong><a href="https://twitter.com/Scytale">@Scytale</a></strong> Weber</li>
<li>Gründungsmitglied des <a href="http://raumzeitlabor.de/">RaumZeitLabor</a></li>
<li>Webentwickler bei <a href="http://www.digi-info.de/">[di]</a></li>
<li>CCC, Piraten, Spackeria</li>
</ul>
</article>
<article>
<h3>Der Vortrag</h3>
<ul>
<li>Langversion unter <a href="http://scy.github.com/javascript-talk/">http://scy.github.com/javascript-talk/</a></li>
<li>hier: weniger Grundlagen, mehr Praxis</li>
<li>nachdrücklicher Buchtipp: <em>JavaScript: The Good Parts</em> (<a href="http://www.oreilly.de/catalog/9780596517748/">O’Reilly</a>, <a href="http://www.amazon.de/JavaScript-Parts-Working-Shallow-Grain/dp/0596517742?tag=raumzeitlabor-21">Amazon</a>)</li>
</ul>
</article>
<article>
<h3>Das Problem</h3>
<ul>
<li>JavaScript von den Machern nicht gut durchdacht</li>
<li>kaum ein JS-Coder hat ein Buch gelesen</li>
<li>erst recht nicht den Standard</li>
<li>alles nur copy&paste-Gefrickel</li>
<li>und dann wundert ihr euch …</li>
</ul>
</article>
<article>
<h3>Wichtige Tipps</h3>
<ul>
<li>benutz ein Framework (möglichst <a href="http://jquery.com/">jQuery</a>)</li>
<li>wenn keine 31 kB Platz,<br/>dann benutz ein Microframework (<a href="http://microjs.com/">microjs.com</a>)</li>
<li>Vorsicht vor Tutorials im Netz<br/>(meist veraltet oder Halbwissen)</li>
<li>benutz <a href="http://getfirebug.com/wiki/index.php/Console_API"><code>console.log()</code> etc.</a> statt <code>alert()</code></li>
</ul>
</article>
<article>
<h3>Variablensichtbarkeit</h3>
<ul>
<li>immer <code>var</code> benutzen (sonst global)
<pre>
function () {
var x = 23;
y = 17; // äquivalent zu window.y = 17;
}
var z = 5; // außerhalb von Funktion, daher global</pre>
</li>
<li>globale explizit über <code>window.xy</code> binden</li>
<li><strong>Variablen nur innerhalb der<br/>definierenden Funktion sichtbar</strong></li>
<li>(Funktionen sind verschachtelbar)</li>
<li>!</li>
</ul>
</article>
<article>
<h3>Globale Variablen stinken</h3>
<ul>
<li>Schlecht:
<pre>
<script>
for (var i = 0; i < 3; i++) {
$('body').append('<p>Absatz ' + i + '</p>');
}
// i ist noch da
</script></pre>
</li>
<li>Besser:
<pre>
<script>
(function () {
for (var i = 0; i < 3; i++) {
$('body').append('<p>Absatz ' + i + '</p>');
}
})();
// i ist weg
</script></pre>
</li>
</ul>
</article>
<article>
<h3>Globale Funktionen stinken</h3>
<ul>
<li>Schlecht:
<pre>
<script>
function showinfo() {
…
}
</script>
<a href="#" onclick="showinfo();">Info</a></pre>
</li>
<li>Besser:
<pre>
<a href="#" id="infolink">Info</a>
<script>
$('#infolink').click(function () {
…
});
</script></pre>
</li>
</ul>
</article>
<article>
<h3>Vermeidbares JavaScript-only</h3>
<ul>
<li>Schlecht:
<pre>
<a href="#" id="infolink">Info</a>
<script>
$('#infolink').click(function () {
// öffne info.html in ner Lightbox
});
</script></pre>
</li>
<li>Besser:
<pre>
<a href="info.html" class="lightboxlink">Info</a>
<script>
$('.lightboxlink').click(function () {
// öffne $(this).attr('href') in ner Lightbox
return false;
});
</script></pre>
</li>
</ul>
</article>
<article>
<h3>Modulpattern</h3>
<ul>
<li>Wenn sich ein globaler Name nicht vermeiden lässt: Genau einen Einstiegspunkt benutzen statt Chaos
<pre>
window.di = window.di || {};
di.JavaScriptTalk = {
speaker: 'Tim Weber',
run: function () {
…
}
};</pre>
<pre>
window.di = window.di || {};
di.NyanCatAnimation = {
enjoyedBy: [ di.JavaScriptTalk.speaker ]
};</pre>
</li>
</ul>
</article>
<article>
<h3>Closures</h3>
<ul>
<li>Objekt mit definierter Schnittstelle<br/>und unerreichbarem Inneren
<pre>
var cat = function (startlives) {
var lives = startlives;
var kill = function () {
lives--;
if (lives < 1) {
alert('Örks');
}
};
return {
kill: kill
};
};
var maunzi = cat(7);
typeof maunzi.lives // undefined</pre>
</li>
</ul>
</article>
<article>
<h3>Schluuuuuss</h3>
<ul>
<li><strong>Fragen?</strong> Jetzt oder nachher oder @Scytale</li>
<li>Slides: <a href="http://scy.github.com/javascript-talk/short.html">http://scy.github.com/javascript-talk/short.html</a></li>
</ul>
<p style="text-align: center;"><img src="qr-short.png" alt="QR-Code" /></p>
</article>
</section>
</body>