js.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 10 Feb 2018 01:28:53 +0200
changeset 2227 1e9323e7ec88
parent 1994 4a272425853d
child 2228 837f1337c59b
permissions -rw-r--r--
Removed files: I don't longer have interest on topic.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1419
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
.. -*- coding: utf-8; -*-
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
=============
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
 JavaScript.
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     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
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     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
b420d5e7e002 Links to ECMA 262 specs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    12
  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Language_Resources
b420d5e7e002 Links to ECMA 262 specs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    13
    Links to ECMA 262 specs.
b420d5e7e002 Links to ECMA 262 specs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    14
1419
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    15
HTML.
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    16
=====
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    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
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    19
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    20
Including JavaScript in HTML page.
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    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
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    24
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    25
  <html>
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    26
    <head>
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    27
      <script type="text/javascript" src="abc.js"></script>
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    28
    </head>
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    29
   ...
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    30
  <html>
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    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
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    40
Inlining JavaScript in HTML code.
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    41
=================================
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    42
::
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    43
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    44
  <html>
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    45
    <h1>Hello!<h1/>
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    46
    <script language="javascript">
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    47
      <!--
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    48
      alert("Hello!")
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    49
      document.write("sin(10) = " + Math.sin(10))
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    50
      //-->
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    51
    </script>
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    52
  </html>
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    53
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    54
Reduce js code size.
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    55
====================
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    56
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    57
  http://crockford.com/javascript/jsmin
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    58
                The JavaScript Minifier
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    59
  http://developer.yahoo.com/yui/compressor/
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    60
                YUI Compressor
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    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
20c7582806da JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1427
diff changeset
    65
  http://www.ecma-international.org/publications/standards/Ecma-262.htm
20c7582806da JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1427
diff changeset
    66
                ECMAScript Language Specification.
1430
8d066d8806b3 Archive of JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1429
diff changeset
    67
  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
    68
                ECMAScript Language Specification.
1429
20c7582806da JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1427
diff changeset
    69
  http://www.ecma-international.org/publications/standards/Ecma-327.htm
20c7582806da JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1427
diff changeset
    70
                ECMAScript 3rd Edition Compact Profile
20c7582806da JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1427
diff changeset
    71
  http://www.ecma-international.org/publications/standards/Ecma-357.htm
20c7582806da JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1427
diff changeset
    72
                ECMAScript for XML (E4X) Specification.
20c7582806da JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1427
diff changeset
    73
  http://www.ecma-international.org/publications/standards/Ecma-290.htm
20c7582806da JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1427
diff changeset
    74
                ECMAScript Components Specification.
20c7582806da JavaScript standards.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1427
diff changeset
    75
1419
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    76
JavaScript versions.
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    77
====================
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    78
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    79
JavaScript 1.5 was introduced back in 1999.
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    80
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    81
  https://developer.mozilla.org/en-US/docs/JavaScript/Reference#JavaScript.2FBrowser_support_history
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    82
                List of versions with CHANGES.
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    83
  http://en.wikipedia.org/wiki/Javascript#Versions
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    84
                List of versions per browser.
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    85
  http://en.wikipedia.org/wiki/ECMAScript#Version_correspondence
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    86
                List of versions.
1599
52d4f3d19b46 ECMAScript 6/7 compatibility table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1534
diff changeset
    87
  http://kangax.github.io/compat-table/es5/
1426
fc39c0ba45d7 ECMAScript 5 compatibility table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1419
diff changeset
    88
                ECMAScript 5 compatibility table.
1599
52d4f3d19b46 ECMAScript 6/7 compatibility table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1534
diff changeset
    89
  http://kangax.github.io/compat-table/es6/
52d4f3d19b46 ECMAScript 6/7 compatibility table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1534
diff changeset
    90
                ECMAScript 6 compatibility table.
52d4f3d19b46 ECMAScript 6/7 compatibility table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1534
diff changeset
    91
  http://kangax.github.io/compat-table/es7/
52d4f3d19b46 ECMAScript 6/7 compatibility table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1534
diff changeset
    92
                ECMAScript 7 compatibility table.
1427
4c3456855f5f Can I use ECMAScript 5 Strict Mode?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1426
diff changeset
    93
  http://caniuse.com/use-strict
4c3456855f5f Can I use ECMAScript 5 Strict Mode?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1426
diff changeset
    94
                Can I use ECMAScript 5 Strict Mode?
1419
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    95
1441
67d287d2e77e Pretty print from JavaScript.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1430
diff changeset
    96
Pretty print from JavaScript.
67d287d2e77e Pretty print from JavaScript.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1430
diff changeset
    97
=============================
1534
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
    98
::
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
    99
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
   100
  console.debug("%o", obj);
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
   101
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
   102
Logging in JS.
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
   103
==============
1441
67d287d2e77e Pretty print from JavaScript.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1430
diff changeset
   104
67d287d2e77e Pretty print from JavaScript.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1430
diff changeset
   105
To Web Developer console (Firefox/Chrome)::
67d287d2e77e Pretty print from JavaScript.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1430
diff changeset
   106
1534
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
   107
  console.log("str");
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
   108
  console.info("str is %s", "str");
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
   109
  console.warn("this is %o", this);
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
   110
  console.error("int: %i, float: %f, string: %s, object: %o", 2, .333, "str", this);
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
   111
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
   112
To see stack-trace use::
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
   113
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
   114
  console.trace();
61deca7da3f5 Logging in JS.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1533
diff changeset
   115
  console.log(new Error().stack); // only FF
1441
67d287d2e77e Pretty print from JavaScript.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1430
diff changeset
   116
1419
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   117
XML from JavaScript.
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   118
====================
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   119
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   120
Powerful, standards-compliant JavaScript XML parser that is designed to help web application
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   121
designers implement cross platform applications that take advantage of client-side manipulation of
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   122
XML data. XML for <SCRIPT> provides a full suite of tools, including:
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   123
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   124
 * A standards-compliant W3C DOM Level 2 processor
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   125
 * An XPath processor
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   126
 * A standards-compliant SAX processor
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   127
 * A simple (classic) DOM processor
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   128
 * Proxies for XML retrieval from any domain
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   129
 * Utilities for XML and application development
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   130
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   131
  http://xmljs.sourceforge.net/
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   132
                home page
9c6c35339ebc JavaScript versions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   133