author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Mon, 22 Feb 2016 13:01:02 +0200 | |
changeset 1906 | 6f6d48f88341 |
parent 1599 | 52d4f3d19b46 |
child 1912 | 8b81a8f0f692 |
permissions | -rw-r--r-- |
1419 | 1 |
.. -*- coding: utf-8; -*- |
2 |
.. include:: HEADER.rst |
|
3 |
||
4 |
============= |
|
5 |
JavaScript. |
|
6 |
============= |
|
1906
6f6d48f88341
Fix TOC declaration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1599
diff
changeset
|
7 |
.. contents:: |
6f6d48f88341
Fix TOC declaration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1599
diff
changeset
|
8 |
:local: |
1419 | 9 |
|
10 |
HTML. |
|
11 |
===== |
|
12 |
||
1533
38f62ec2f1ed
Including JavaScript in HTML page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1441
diff
changeset
|
13 |
``<noscript>`` tag used to render HTML if JavaScript disabled in browser. |
1419 | 14 |
|
15 |
Including JavaScript in HTML page. |
|
16 |
================================== |
|
1533
38f62ec2f1ed
Including JavaScript in HTML page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1441
diff
changeset
|
17 |
|
38f62ec2f1ed
Including JavaScript in HTML page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1441
diff
changeset
|
18 |
In ``head``:: |
1419 | 19 |
|
20 |
<html> |
|
21 |
<head> |
|
22 |
<script type="text/javascript" src="abc.js"></script> |
|
23 |
</head> |
|
24 |
... |
|
25 |
<html> |
|
26 |
||
1533
38f62ec2f1ed
Including JavaScript in HTML page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1441
diff
changeset
|
27 |
or alternatively just before closing ``body``:: |
38f62ec2f1ed
Including JavaScript in HTML page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1441
diff
changeset
|
28 |
|
38f62ec2f1ed
Including JavaScript in HTML page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1441
diff
changeset
|
29 |
<script src="abc.js"></script> |
38f62ec2f1ed
Including JavaScript in HTML page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1441
diff
changeset
|
30 |
</body> |
38f62ec2f1ed
Including JavaScript in HTML page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1441
diff
changeset
|
31 |
<html> |
38f62ec2f1ed
Including JavaScript in HTML page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1441
diff
changeset
|
32 |
|
38f62ec2f1ed
Including JavaScript in HTML page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1441
diff
changeset
|
33 |
**NOTE** ``type="text/javascript"`` no longer necessary. |
38f62ec2f1ed
Including JavaScript in HTML page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1441
diff
changeset
|
34 |
|
1419 | 35 |
Inlining JavaScript in HTML code. |
36 |
================================= |
|
37 |
:: |
|
38 |
||
39 |
<html> |
|
40 |
<h1>Hello!<h1/> |
|
41 |
<script language="javascript"> |
|
42 |
<!-- |
|
43 |
alert("Hello!") |
|
44 |
document.write("sin(10) = " + Math.sin(10)) |
|
45 |
//--> |
|
46 |
</script> |
|
47 |
</html> |
|
48 |
||
49 |
Reduce js code size. |
|
50 |
==================== |
|
51 |
||
52 |
http://crockford.com/javascript/jsmin |
|
53 |
The JavaScript Minifier |
|
54 |
http://developer.yahoo.com/yui/compressor/ |
|
55 |
YUI Compressor |
|
56 |
||
1429
20c7582806da
JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1427
diff
changeset
|
57 |
JavaScript standards. |
20c7582806da
JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1427
diff
changeset
|
58 |
===================== |
20c7582806da
JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1427
diff
changeset
|
59 |
|
20c7582806da
JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1427
diff
changeset
|
60 |
http://www.ecma-international.org/publications/standards/Ecma-262.htm |
20c7582806da
JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1427
diff
changeset
|
61 |
ECMAScript Language Specification. |
1430
8d066d8806b3
Archive of JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1429
diff
changeset
|
62 |
http://www.ecma-international.org/publications/standards/Ecma-262-arch.htm |
8d066d8806b3
Archive of JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1429
diff
changeset
|
63 |
ECMAScript Language Specification. |
1429
20c7582806da
JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1427
diff
changeset
|
64 |
http://www.ecma-international.org/publications/standards/Ecma-327.htm |
20c7582806da
JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1427
diff
changeset
|
65 |
ECMAScript 3rd Edition Compact Profile |
20c7582806da
JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1427
diff
changeset
|
66 |
http://www.ecma-international.org/publications/standards/Ecma-357.htm |
20c7582806da
JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1427
diff
changeset
|
67 |
ECMAScript for XML (E4X) Specification. |
20c7582806da
JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1427
diff
changeset
|
68 |
http://www.ecma-international.org/publications/standards/Ecma-290.htm |
20c7582806da
JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1427
diff
changeset
|
69 |
ECMAScript Components Specification. |
20c7582806da
JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1427
diff
changeset
|
70 |
|
1419 | 71 |
JavaScript versions. |
72 |
==================== |
|
73 |
||
74 |
JavaScript 1.5 was introduced back in 1999. |
|
75 |
||
76 |
https://developer.mozilla.org/en-US/docs/JavaScript/Reference#JavaScript.2FBrowser_support_history |
|
77 |
List of versions with CHANGES. |
|
78 |
http://en.wikipedia.org/wiki/Javascript#Versions |
|
79 |
List of versions per browser. |
|
80 |
http://en.wikipedia.org/wiki/ECMAScript#Version_correspondence |
|
81 |
List of versions. |
|
1599
52d4f3d19b46
ECMAScript 6/7 compatibility table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1534
diff
changeset
|
82 |
http://kangax.github.io/compat-table/es5/ |
1426
fc39c0ba45d7
ECMAScript 5 compatibility table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1419
diff
changeset
|
83 |
ECMAScript 5 compatibility table. |
1599
52d4f3d19b46
ECMAScript 6/7 compatibility table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1534
diff
changeset
|
84 |
http://kangax.github.io/compat-table/es6/ |
52d4f3d19b46
ECMAScript 6/7 compatibility table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1534
diff
changeset
|
85 |
ECMAScript 6 compatibility table. |
52d4f3d19b46
ECMAScript 6/7 compatibility table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1534
diff
changeset
|
86 |
http://kangax.github.io/compat-table/es7/ |
52d4f3d19b46
ECMAScript 6/7 compatibility table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1534
diff
changeset
|
87 |
ECMAScript 7 compatibility table. |
1427
4c3456855f5f
Can I use ECMAScript 5 Strict Mode?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1426
diff
changeset
|
88 |
http://caniuse.com/use-strict |
4c3456855f5f
Can I use ECMAScript 5 Strict Mode?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1426
diff
changeset
|
89 |
Can I use ECMAScript 5 Strict Mode? |
1419 | 90 |
|
1441
67d287d2e77e
Pretty print from JavaScript.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1430
diff
changeset
|
91 |
Pretty print from JavaScript. |
67d287d2e77e
Pretty print from JavaScript.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1430
diff
changeset
|
92 |
============================= |
1534 | 93 |
:: |
94 |
||
95 |
console.debug("%o", obj); |
|
96 |
||
97 |
Logging in JS. |
|
98 |
============== |
|
1441
67d287d2e77e
Pretty print from JavaScript.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1430
diff
changeset
|
99 |
|
67d287d2e77e
Pretty print from JavaScript.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1430
diff
changeset
|
100 |
To Web Developer console (Firefox/Chrome):: |
67d287d2e77e
Pretty print from JavaScript.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1430
diff
changeset
|
101 |
|
1534 | 102 |
console.log("str"); |
103 |
console.info("str is %s", "str"); |
|
104 |
console.warn("this is %o", this); |
|
105 |
console.error("int: %i, float: %f, string: %s, object: %o", 2, .333, "str", this); |
|
106 |
||
107 |
To see stack-trace use:: |
|
108 |
||
109 |
console.trace(); |
|
110 |
console.log(new Error().stack); // only FF |
|
1441
67d287d2e77e
Pretty print from JavaScript.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1430
diff
changeset
|
111 |
|
1419 | 112 |
XML from JavaScript. |
113 |
==================== |
|
114 |
||
115 |
Powerful, standards-compliant JavaScript XML parser that is designed to help web application |
|
116 |
designers implement cross platform applications that take advantage of client-side manipulation of |
|
117 |
XML data. XML for <SCRIPT> provides a full suite of tools, including: |
|
118 |
||
119 |
* A standards-compliant W3C DOM Level 2 processor |
|
120 |
* An XPath processor |
|
121 |
* A standards-compliant SAX processor |
|
122 |
* A simple (classic) DOM processor |
|
123 |
* Proxies for XML retrieval from any domain |
|
124 |
* Utilities for XML and application development |
|
125 |
||
126 |
http://xmljs.sourceforge.net/ |
|
127 |
home page |
|
128 |