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