-
Notifications
You must be signed in to change notification settings - Fork 1
/
2013-04-23.html
392 lines (234 loc) · 10.1 KB
/
2013-04-23.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<!DOCTYPE html>
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta name="description" content="Client Server Web Architecture includes REST inspired Web APIs, significant JavaScript client side processing and Java or other server side language (many of which are available on the Java Virtual Machine).">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width" />
<title>Client Server Web Application Development - webapis</title>
<link rel="stylesheet" href="css/normalize.css" />
<link rel="stylesheet" href="css/foundation.min.css" />
<link rel="stylesheet" href="js/assets/base.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<style>
body {line-height: 1.4;}
html { overflow-y: scroll !important;}
img {height: 25px;}
pre {
font-size: 12px;
line-height: 1
padding: 15px;
white-space: pre; /* CSS2 */
white-space: pre-wrap; /* CSS 2.1 */
white-space: pre-line; /* CSS 3 (and 2.1 as well, actually) */
word-wrap: break-word; /* IE */
overflow: auto;
}
span.tag{
position:relative;
left:-10px;
}
div.box {
position:relative;
width:90px;
height:20px;
top:-10px;
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
border-radius: 12px;
border:27px solid #FFFF00;
background-color:#F2AD0C;
-webkit-box-shadow: #B3B3B3 5px 5px 5px;
-moz-box-shadow: #B3B3B3 5px 5px 5px;
box-shadow: #B3B3B3 5px 5px 5px;
-webkit-transform: rotate(20deg);
-moz-transform: rotate(20deg);
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); /*for IE*/
-o-transform: rotate(20deg);}
div.jvm {color:red;}
div.webapis{color:blue;}
div.javascript{color: green;}
div.java{color: purple;}
</style>
<script src="js/vendor/custom.modernizr.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-40376887-1', 'clientserverweb.com');
ga('send', 'pageview');
</script>
</head>
<body>
<nav class="top-bar">
<ul class="title-area">
<li class="name">
<h1><a href='/'>Client Server Web Applications</a></h1>
</li>
<li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
</ul>
<section class="top-bar-section">
<!-- Left Nav Section -->
<ul class="left">
</ul>
<ul class="right">
<li class="active"><a href="jvm.html">JVM</a></li>
<li class="active"><a href="java.html">Java</a></li>
<li class="divider"></li>
<li><a href="javascript.html">JavaScript</a></li>
<li><a href="webapis.html">Web APIs</a></li>
<li class="divider hide-for-small"></li>
<li><a href="about.html">About</a></li>
</ul>
</section>
</nav>
<div class="row">
<div class="large-2 columns">
<h4>2013-04-23</h4>
<div class='box javascript'><span class='tag'>javascript</span></div>
</div>
<div class="large-10 columns">
<div class="panel">
<p>
<h4>Quick JavaScript Debugging Tricks</h4>
<p>Java developers generally do their work in a cycle of code, build (compile), execute.
The Java Virtual Machine included a HotSwap feature since 2002. Later this functionality was added into
the Instrumentation API. This allows for limited update to class bytecode in place
(now commonly used in debuggers). JRebel is a commercial third party product that allows for
far more extensive reloading of java classes.</p>
<p>Limitations on reloading code in this way simply don't exist in JavaScript. Without going into the details of why this is possible,
the following are a few examples of how code can quickly and easily be modified. This results in the possibility of
a very different workflow while working in JavaScript. The fact that coding can be done in the browser console itself is significant.
A cursory knowledge of JavaScript's capabilities and modern browsers means that JavaScript can be modified and debugged on almost any web page
(even those in a production environments) which can allow for quick identification of problems and corresponding solutions.
</p>
<p>The following are a few simple techniques available in JavaScript that take advantage of its relatively
dynamic nature and allow you to extensively modify the behavior of any web page you like.
</p>
<h5>Add a Script to a Page</h5>
<p>
JavaScript <a href="http://en.wikipedia.org/wiki/Bookmarklet">bookmarklets</a> are a popular example of the ability to add JavaScript to a page.
Some are fun (like <a href="http://fontbomb.ilex.ca/">fontbomb</a>) but they can also be used for development
(for example the <a href="http://www.learningjquery.com/2006/12/jquerify-bookmarklet">jQuery bookmarklet</a>).
With a few lines of code in the browser console, you can include a publicly available JavaScript file into a page. <a href="https://developers.google.com/speed/libraries/devguide">Google</a> and others Content Delivery Networks host popular JavaScript libraries so there are plenty readily available.
</p>
This example uses Native JavaScript to include jQuery in a page:
<pre>
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js';
document.head.appendChild(script);
</pre>
<p>
If jQuery is already available, you can use it and grab a script in a single function call:
<pre>
$.getScript('http://underscorejs.org/underscore-min.js');
</pre>
</p>
<p>
If you ran both of these commands in a page that includes some list items (li tags), the following will
show both in action - underscorejs's each() function and a jQuery selector.
<pre>
_.each($('li'), function(li){console.log(li)});
</pre>
</p>
<h5>Modify an existing page</h5>
<p>
To change an attribute of a DOM Element:
Navigate to <a href="http://oreilly.com/">http://oreilly.com/</a> and you can resize the logo like so:
<pre>
$('.logo a img').width('400px');
</pre>
Similarly, you can change the value of a variable or text:
<pre>
$('span.item').first().text('Really Popular Topics:');
</pre>
There are even ways to override an <a href="http://www.bennadel.com/blog/1624-Ask-Ben-Overriding-Core-jQuery-Methods.htm">existing library's functions.</a>.
</p>
<p>Modifying a JavaScript objects prototype allows allows you to change the behavior of existing objects. If we start with an existing
function that modifies the argument passed to it (in this case, trimming leading whitespace).
<pre>
function ltrim(str)
{
return str.replace(/^[ \t]+/, '');
}
var text = ' This is a Test!';
ltrim(text)
</pre>
Now modify the function so that it will use "this" - the containing object in this context (and remove the parameter). Assign the
function to the String prototype. Now all JavaScript objects that have String as their prototype can have ltrim() called on them
and will return the String with it's leading whitespace removed.
<pre>
function ltrim()
{
return this.replace(/^[ \t]+/, '');
}
String.prototype.ltrim = ltrim;
text.trim()
</pre>
</p>
<p>
Some of the very characteristics that make JavaScript difficult (handling of scope, availability of globals) also make it
rather easy to manipulate pages wherever they may be. None of the techniques above are introduced because they are particularly valuable
when coding a specific application. They are extremely useful when debugging and troubleshooting pages in arbitrary
environments, and allow for quick iterations when experimenting with new code.
</p>
</p>
</div>
</div>
</div>
<div class="row">
<div class="large-2 columns">
</div>
<div class="large-10 columns">
<!-- REPO -->
</div>
</div>
<div class="row">
<div class="large-2 columns">
<a href="rss.xml"><img src='/img/rss.jpeg' /></a>
</div>
<div class="large-10 columns">
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'clientserverweb';
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
</div>
<script>
document.write('<script src=' +
('__proto__' in {} ? 'js/vendor/zepto' : 'js/vendor/jquery') +
'.js><\/script>')
</script>
<script src="js/foundation.min.js"></script>
<!--
<script src="js/foundation/foundation.js"></script>
<script src="js/foundation/foundation.alerts.js"></script>
<script src="js/foundation/foundation.clearing.js"></script>
<script src="js/foundation/foundation.cookie.js"></script>
<script src="js/foundation/foundation.dropdown.js"></script>
<script src="js/foundation/foundation.forms.js"></script>
<script src="js/foundation/foundation.joyride.js"></script>
<script src="js/foundation/foundation.magellan.js"></script>
<script src="js/foundation/foundation.orbit.js"></script>
<script src="js/foundation/foundation.placeholder.js"></script>
<script src="js/foundation/foundation.reveal.js"></script>
<script src="js/foundation/foundation.section.js"></script>
<script src="js/foundation/foundation.tooltips.js"></script>
<script src="js/foundation/foundation.topbar.js"></script>
-->
<script>
$(document).foundation();
</script>
</body>
</html>