Whereas HTML 定义网页的结构和内容而 CSS 设置格式和外观, JavaScript 向网页添加交互性并创建富 Web 应用程序。
However, the umbrella term "JavaScript" as understood in a web browser context contains several very different elements. One of them is the core language (ECMAScript), another is the collection of the Web API , including the DOM (Document Object Model).
JavaScript 核心语言被 ECMA TC39 委员会标准化为一种语言名为 ECMAScript .
此核心语言还被用于非浏览器环境,例如在 node.js .
Among other things, ECMAScript defines:
throw
,
try...catch
, ability to create user-defined
Error
types)
window
object, but ECMAScript only defines the APIs not specific to browsers, e.g.
parseInt
,
parseFloat
,
decodeURI
,
encodeURI
...
JSON
,
Math
,
Array.prototype
methods,
Object
introspection methods, etc.)
As of October 2016, the current versions of the major Web browsers implement ECMAScript 5.1 and ECMAScript 2015 , but older versions (still in use) implement ECMAScript 5 only.
The major 6th Edition of ECMAScript was officially approved and published as a standard on June 17, 2015 by the ECMA General Assembly. Since then ECMAScript Editions are published on a yearly basis.
ECMAScript 国际化 API 规范
is an addition to the ECMAScript Language Specification, also standardized by Ecma TC39. The internationalization API provides collation (string comparison), number formatting, and date-and-time formatting for JavaScript applications, letting the applications choose the language and tailor the functionality to their needs. The initial standard was approved in December 2012; the status of implementations in browsers is tracked in the documentation of the
Intl
object. The Internationalization specification is nowadays also ratified on a yearly basis and browsers constantly improve their implementation.
WebIDL 规范 provides the glue between the DOM technologies and ECMAScript.
The Document Object Model (DOM) is a cross-platform, language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. Objects in the DOM 树 may be addressed and manipulated by using methods on the objects. The W3C standardizes the Core Document Object Model, which defines language-agnostic interfaces that abstract HTML and XML documents as objects, and also defines mechanisms to manipulate this abstraction. Among the things defined by the DOM, we can find:
Node
,
Element
,
DocumentFragment
,
Document
,
DOMImplementation
,
Event
,
EventTarget
, …
From the ECMAScript point of view, objects defined in the DOM specification are called "host objects".
HTML
, the Web's markup language, is specified in terms of the DOM. Layered above the abstract concepts defined in DOM Core, HTML also defines the
meaning
of elements. The HTML DOM includes such things as the
className
property on HTML elements, or APIs such as
document.body
.
The HTML specification also defines restrictions on documents; for example, it requires all children of a
<ul>
element, which represents an unordered list, to be
<li>
elements, as those represent list items. In general, it also forbids using elements and attributes that aren't defined in a standard.
Looking for the
Document
对象,
Window
object, and the other DOM elements? Read the
DOM documentation
.
setTimeout
and
setInterval
functions were first specified on the
Window
interface in HTML Standard.
<canvas>
.