mozilla

版本 268337 / JavaScript总览

  • 版本网址缩略名: Core_JavaScript_1.5_Guide/JavaScript总览
  • 版本标题: JavaScript总览
  • 版本 id: 268337
  • 创建于:
  • 创建者: Tingod
  • 是否是当前版本?
  • 评论 New page: <breadcrumbs></breadcrumbs> == 什么是JavaScript? == JavaScript 是一种跨平台、面向对象的脚本语言。JavaScript是一个小的,轻量级的语言;不能被用作独...

修订内容

什么是JavaScript?

JavaScript 是一种跨平台、面向对象的脚本语言。JavaScript是一个小的,轻量级的语言;不能被用作独立语言,但是可以嵌入到其他产品或应用程序中,如Web 浏览器。在一个主机环境下,JavaScript可与同环境其他对象相连,并在其之上提供计划性的控制。

核心JavaScript包含一套核心对象,如ArrayDate以及 Math,以及一套核心的语言元素如运算符,控制结构,以及生命。核心JavaScript可以通过补充各种附加对象的方式扩展至各种用途,如:

  • 客户端JavaScript 提供控制浏览器及其文档对象模型(DOM,Document Object Model)的对象,扩展了核心JavaScript。比如,客户端的扩展允许应用在一个HTML表单(Form)中防止元素,并对鼠标点击,表单输入以及页面导航等用户时间进行响应。
  • 服务器端JavaScript 提供与使JavaScript在服务器端运行的对象。如,服务器端的扩展允许应用程序与关系数据库通信,提供从一个invocation到另一个应用的信息的连贯性,或在服务器上进行文件处理。

通过JavaScript的LiveConnect功能,你可以让Java与JavaScript代码互相通信。在JavaScript中你可以实例化Java对象并访问其公用方法和字段。在Java中你也可以访问JavaScript对象,属性以及方法。

Netscape发明了JavaScript,JavaScrips首先应用于Netscape的浏览器。

JavaScript和Java

JavaScript与Java在某些方面有些相似, 但在其他方面是完全不同的。JavaScript语言与Java类似,但是没有Java有的静态分类以及强壮的类型检查。 JavaScript支持大部分的Java表达式语法以及基本的控制流结构。

与Java 由通过声明创建的类组成的编译系统相比,JavaScript只支持有几个代表数字,布尔以及字符值的数据类型为基础的运行时系统。 JavaScript有一个基于原型(prototype-based)的对象模型,用之取代更为通用的基于类(object-based)的对象模型。基于原型的模型支持动态继承;也就是说,可对每个独立对象进行不同的继承。JavaScript还支持不用特别声明的函数(Functions) 。Functions还可以是对象的属性,如同执行宽松类型的方法。

同Java相比,JavaScript实在是一种格式自由的语言。你不需要生命所有的变量,类以及方法。你不用关心方法是公有(Public)还是私有(Private)或者被保护(Protected),也不用实例化接口。变量,参数以及函数返回值都都没有明确的类型。

Java 是一种基于类的编程语言,为了快速执行和类型安全的目的而设计。类型安全意味着,例如,你不能将一个Java数值类型(integer)指向一个对象引用,或者通过混淆Java字节码来访问私有内存。 Java的基于类的模型意味着程序仅有类及其方法。Java的类继承以及健壮的类型声明需要紧密耦合的对象层次。这些要求使Java编程比 JavaScript的创建更加复杂。

相比之下,JavaScript的灵魂来源于那些小型的动态类型化的语言如HyperTalk 和 dBASE。这些脚本语言为更多的受众提供了编程工具,因为他们有简单的语法,特有的嵌入功能性,以及对对象创建的更少的要求。

JavaScript Java
面向对象。对象类型间无区别。通过原型机制实现继承,属性和方法可以动态加载至任何对象。 基于类。对象划分为类和实例,通过类层次实现集成。类和实例不能动态加载属性和方法。
Variable data types not declared (dynamic typing). Variable data types must be declared (static typing).
Cannot automatically write to hard disk. Cannot automatically write to hard disk.

Table 1.1: JavaScript compared to Java

关于JavaScript与Java区别性的更多信息,请参阅章节 Details of the Object Model

JavaScript和ECMA规范

Netscape invented JavaScript, and JavaScript was first used in Netscape browsers. However, Netscape is working with Ecma International - the European association for standardizing information and communication systems (formerly known as ECMA - the European Computer Manufacturers Association) to deliver a standardized, international programming language based on core JavaScript. This standardized version of JavaScript, called ECMAScript, behaves the same way in all applications that support the standard. Companies can use the open standard language to develop their implementation of JavaScript. The ECMAScript standard is documented in the ECMA-262 specification.

The ECMA-262 standard is also approved by the ISO (International Organization for Standardization) as ISO-16262. You can find a PDF version of ECMA-262 at the Mozilla website. You can also find the specification on the Ecma International website. The ECMAScript specification does not describe the Document Object Model (DOM), which is standardized by the World Wide Web Consortium (W3C). The DOM defines the way in which HTML document objects are exposed to your script.

JavaScript和ECMA版本之间的关系

Netscape worked closely with Ecma International to produce the ECMAScript Specification (ECMA-262). The following table describes the relationship between JavaScript versions and ECMAScript editions.

JavaScript version Relationship to ECMAScript edition
JavaScript 1.1 ECMA-262, Edition 1 is based on JavaScript 1.1.
JavaScript 1.2 ECMA-262 was not complete when JavaScript 1.2 was released. JavaScript 1.2 is not fully compatible with ECMA-262, Edition 1, for the following reasons:
  • Netscape developed additional features in JavaScript 1.2 that were not considered for ECMA-262.
  • ECMA-262 adds two new features: internationalization using Unicode, and uniform behavior across all platforms. Several features of JavaScript 1.2, such as the Date object, were platform-dependent and used platform-specific behavior.

JavaScript 1.3

JavaScript 1.3 is fully compatible with ECMA-262, Edition 1.

JavaScript 1.3 resolved the inconsistencies that JavaScript 1.2 had with ECMA-262, while keeping all the additional features of JavaScript 1.2 except == and !=, which were changed to conform with ECMA-262.

JavaScript 1.4

JavaScript 1.4 is fully compatible with ECMA-262, Edition 1.

The third version of the ECMAScript specification was not finalized when JavaScript 1.4 was released.

JavaScript 1.5 JavaScript 1.5 is fully compatible with ECMA-262, Edition 3.

Table 1.2: JavaScript versions and ECMAScript editions

Note: ECMA-262, Edition 2 consisted of minor editorial changes and bug fixes to the Edition 1 specification. The TC39 working group of Ecma International is currently working on ECMAScript Edition 4, which will correspond to a future release of JavaScript, JavaScript 2.0.

The Core JavaScript Reference indicates which features of the language are ECMAScript-compliant.

JavaScript will always include features that are not part of the ECMAScript Specification; JavaScript is compatible with ECMAScript, while providing additional features.

JavaScript Documentation与ECMA规范对比

The ECMAScript specification is a set of requirements for implementing ECMAScript; it is useful if you want to determine whether a JavaScript feature is supported in other ECMAScript implementations. If you plan to write JavaScript code that uses only features supported by ECMAScript, then you may need to review the ECMAScript specification.

The ECMAScript document is not intended to help script programmers; use the JavaScript documentation for information on writing scripts.

JavaScript和ECMA的术语

The ECMAScript specification uses terminology and syntax that may be unfamiliar to a JavaScript programmer. Although the description of the language may differ in ECMAScript, the language itself remains the same. JavaScript supports all functionality outlined in the ECMAScript specification.

The JavaScript documentation describes aspects of the language that are appropriate for a JavaScript programmer. For example:

  • The Global Object is not discussed in the JavaScript documentation because you do not use it directly. The methods and properties of the Global Object, which you do use, are discussed in the JavaScript documentation but are called top-level functions and properties.
  • The no parameter (zero-argument) constructor with the Number and String objects is not discussed in the JavaScript documentation, because what is generated is of little use. A Number constructor without an argument returns +0, and a String constructor without an argument returns "" (an empty string).

{{template.PreviousNext("Core_JavaScript_1.5_Guide:About", "Core_JavaScript_1.5_Guide:Values")}}


{{ wiki.languages( { "es": "es/Gu\u00eda_JavaScript_1.5/Concepto_de_JavaScript", "fr": "fr/Guide_JavaScript_1.5/Aper\u00e7u_de_JavaScript", "ja": "ja/Core_JavaScript_1.5_Guide/JavaScript_Overview", "ko": "ko/Core_JavaScript_1.5_Guide/JavaScript_Overview", "pl": "pl/Przewodnik_po_j\u0119zyku_JavaScript_1.5/Przegl\u0105d_JavaScriptu" } ) }}

修订版来源

<p>
</p>
<h3 name=".E4.BB.80.E4.B9.88.E6.98.AFJavaScript.EF.BC.9F"> 什么是JavaScript? </h3>
<p>JavaScript 是一种跨平台、面向对象的脚本语言。JavaScript是一个小的,轻量级的语言;不能被用作独立语言,但是可以嵌入到其他产品或应用程序中,如Web 浏览器。在一个主机环境下,JavaScript可与同环境其他对象相连,并在其之上提供计划性的控制。
</p><p>核心JavaScript包含一套核心对象,如<code>Array</code>,<code>Date</code>以及 <code>Math</code>,以及一套核心的语言元素如运算符,控制结构,以及生命。核心JavaScript可以通过补充各种附加对象的方式扩展至各种用途,如:
</p>
<ul><li> <i>客户端JavaScript</i> 提供控制浏览器及其文档对象模型(DOM,Document Object Model)的对象,扩展了核心JavaScript。比如,客户端的扩展允许应用在一个HTML表单(Form)中防止元素,并对鼠标点击,表单输入以及页面导航等用户时间进行响应。
</li><li> <i>服务器端JavaScript</i> 提供与使JavaScript在服务器端运行的对象。如,服务器端的扩展允许应用程序与关系数据库通信,提供从一个invocation到另一个应用的信息的连贯性,或在服务器上进行文件处理。
</li></ul>
<p>通过JavaScript的LiveConnect功能,你可以让Java与JavaScript代码互相通信。在JavaScript中你可以实例化Java对象并访问其公用方法和字段。在Java中你也可以访问JavaScript对象,属性以及方法。
</p><p>Netscape发明了JavaScript,JavaScrips首先应用于Netscape的浏览器。
</p>
<h3 name="JavaScript.E5.92.8CJava"> JavaScript和Java </h3>
<p>JavaScript与Java在某些方面有些相似, 但在其他方面是完全不同的。JavaScript语言与Java类似,但是没有Java有的静态分类以及强壮的类型检查。 JavaScript支持大部分的Java表达式语法以及基本的控制流结构。
</p><p>与Java 由通过声明创建的类组成的编译系统相比,JavaScript只支持有几个代表数字,布尔以及字符值的数据类型为基础的运行时系统。 JavaScript有一个基于原型(prototype-based)的对象模型,用之取代更为通用的基于类(object-based)的对象模型。基于原型的模型支持动态继承;也就是说,可对每个独立对象进行不同的继承。JavaScript还支持不用特别声明的函数(Functions) 。Functions还可以是对象的属性,如同执行宽松类型的方法。
</p><p>同Java相比,JavaScript实在是一种格式自由的语言。你不需要生命所有的变量,类以及方法。你不用关心方法是公有(Public)还是私有(Private)或者被保护(Protected),也不用实例化接口。变量,参数以及函数返回值都都没有明确的类型。
</p><p>Java 是一种基于类的编程语言,为了快速执行和类型安全的目的而设计。类型安全意味着,例如,你不能将一个Java数值类型(integer)指向一个对象引用,或者通过混淆Java字节码来访问私有内存。 Java的基于类的模型意味着程序仅有类及其方法。Java的类继承以及健壮的类型声明需要紧密耦合的对象层次。这些要求使Java编程比 JavaScript的创建更加复杂。
</p><p>相比之下,JavaScript的灵魂来源于那些小型的动态类型化的语言如HyperTalk 和 dBASE。这些脚本语言为更多的受众提供了编程工具,因为他们有简单的语法,特有的嵌入功能性,以及对对象创建的更少的要求。
</p>
<table class="fullwidth-table">
<tbody><tr>
<th>JavaScript</th>
<th>Java</th>
</tr>
<tr>
<td>面向对象。对象类型间无区别。通过原型机制实现继承,属性和方法可以动态加载至任何对象。</td>
<td>基于类。对象划分为类和实例,通过类层次实现集成。类和实例不能动态加载属性和方法。</td>
</tr>
<tr>
<td>Variable data types not declared (dynamic typing).</td>
<td>Variable data types must be declared (static typing).</td>
</tr>
<tr>
<td>Cannot automatically write to hard disk.</td>
<td>Cannot automatically write to hard disk.</td>
</tr>
</tbody></table>
<p><small><b>Table 1.1: JavaScript compared to Java</b></small><br>
<br>
关于JavaScript与Java区别性的更多信息,请参阅章节 <a href="cn/Core_JavaScript_1.5_Guide#Details_of_the_Object_Model">Details of the Object Model</a>。
</p>
<h3 name="JavaScript.E5.92.8CECMA.E8.A7.84.E8.8C.83"> JavaScript和ECMA规范 </h3>
<p>Netscape invented JavaScript, and JavaScript was first used in Netscape browsers. However, Netscape is working with <a class="external" href="http://www.ecma-international.org/">Ecma International</a> - the European association for standardizing information and communication systems (formerly known as ECMA - the European Computer Manufacturers Association) to deliver a standardized, international programming language based on core JavaScript. This standardized version of JavaScript, called ECMAScript, behaves the same way in all applications that support the standard. Companies can use the open standard language to develop their implementation of JavaScript. The ECMAScript standard is documented in the ECMA-262 specification.
</p><p>The ECMA-262 standard is also approved by the <a class="external" href="http://www.iso.ch/">ISO</a> (International Organization for Standardization) as ISO-16262. You can find a <a class="external" href="http://www.mozilla.org/js/language/E262-3.pdf">PDF version of ECMA-262</a> at the Mozilla website. You can also find the specification on <a class="external" href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">the Ecma International website</a>. The ECMAScript specification does not describe the Document Object Model (DOM), which is standardized by the <a class="external" href="http://www.w3.org/">World Wide Web Consortium (W3C)</a>. The DOM defines the way in which HTML document objects are exposed to your script.
</p>
<h4 name="JavaScript.E5.92.8CECMA.E7.89.88.E6.9C.AC.E4.B9.8B.E9.97.B4.E7.9A.84.E5.85.B3.E7.B3.BB"> JavaScript和ECMA版本之间的关系 </h4>
<p>Netscape worked closely with Ecma International to produce the ECMAScript Specification (ECMA-262). The following table describes the relationship between JavaScript versions and ECMAScript editions.
</p>
<table class="fullwidth-table">
<tbody><tr>
<th>JavaScript version</th>
<th>Relationship to ECMAScript edition</th>
</tr>
<tr>
<td>JavaScript 1.1</td>
<td>ECMA-262, Edition 1 is based on JavaScript 1.1.</td>
</tr>
<tr>
<td>JavaScript 1.2</td>
<td>ECMA-262 was not complete when JavaScript 1.2 was released. JavaScript 1.2 is not fully compatible with ECMA-262, Edition 1, for the following reasons:
<ul><li> Netscape developed additional features in JavaScript 1.2 that were not considered for ECMA-262.
</li><li> ECMA-262 adds two new features: internationalization using Unicode, and uniform behavior across all platforms. Several features of JavaScript 1.2, such as the Date object, were platform-dependent and used platform-specific behavior.</li></ul></td>

</tr>
<tr>
<td><p>JavaScript 1.3</p></td>
<td><p>JavaScript 1.3 is fully compatible with ECMA-262, Edition 1.</p>
<p>JavaScript 1.3 resolved the inconsistencies that JavaScript 1.2 had with ECMA-262, while keeping all the additional features of JavaScript 1.2 except == and !=, which were changed to conform with ECMA-262.</p></td>
</tr>
<tr>
<td><p>JavaScript 1.4</p></td>
<td><p>JavaScript 1.4 is fully compatible with ECMA-262, Edition 1.</p>
<p>The third version of the ECMAScript specification was not finalized when JavaScript 1.4 was released.</p></td>
</tr>
<tr>
<td>JavaScript 1.5</td>
<td>JavaScript 1.5 is fully compatible with ECMA-262, Edition 3.</td>
</tr>
</tbody></table>
<p><small><b>Table 1.2: JavaScript versions and ECMAScript editions</b></small><br>
<br>
</p>
<div class="note"><b>Note</b>: ECMA-262, Edition 2 consisted of minor editorial changes and bug fixes to the Edition 1 specification. The TC39 working group of Ecma International is currently working on ECMAScript Edition 4, which will correspond to a future release of JavaScript, JavaScript 2.0.</div>
<p>The <a href="cn/Core_JavaScript_1.5_Reference">Core JavaScript Reference</a> indicates which features of the language are ECMAScript-compliant.
</p><p>JavaScript will always include features that are not part of the ECMAScript Specification; JavaScript is compatible with ECMAScript, while providing additional features.
</p>
<h4 name="JavaScript_Documentation.E4.B8.8EECMA.E8.A7.84.E8.8C.83.E5.AF.B9.E6.AF.94"> JavaScript Documentation与ECMA规范对比 </h4>
<p>The ECMAScript specification is a set of requirements for implementing ECMAScript; it is useful if you want to determine whether a JavaScript feature is supported in other ECMAScript implementations. If you plan to write JavaScript code that uses only features supported by ECMAScript, then you may need to review the ECMAScript specification.
</p><p>The ECMAScript document is not intended to help script programmers; use the JavaScript documentation for information on writing scripts.
</p>
<h4 name="JavaScript.E5.92.8CECMA.E7.9A.84.E6.9C.AF.E8.AF.AD"> JavaScript和ECMA的术语 </h4>
<p>The ECMAScript specification uses terminology and syntax that may be unfamiliar to a JavaScript programmer. Although the description of the language may differ in ECMAScript, the language itself remains the same. JavaScript supports all functionality outlined in the ECMAScript specification.
</p><p>The JavaScript documentation describes aspects of the language that are appropriate for a JavaScript programmer. For example:
</p>
<ul><li> The Global Object is not discussed in the JavaScript documentation because you do not use it directly. The methods and properties of the Global Object, which you do use, are discussed in the JavaScript documentation but are called top-level functions and properties.
</li><li> The no parameter (zero-argument) constructor with the <code>Number</code> and <code>String</code> objects is not discussed in the JavaScript documentation, because what is generated is of little use. A <code>Number</code> constructor without an argument returns +0, and a <code>String</code> constructor without an argument returns "" (an empty string).
</li></ul>
<p>{{template.PreviousNext("Core_JavaScript_1.5_Guide:About", "Core_JavaScript_1.5_Guide:Values")}}
</p><p><br>
</p>
<div class="noinclude">
</div>
{{ wiki.languages( { "es": "es/Gu\u00eda_JavaScript_1.5/Concepto_de_JavaScript", "fr": "fr/Guide_JavaScript_1.5/Aper\u00e7u_de_JavaScript", "ja": "ja/Core_JavaScript_1.5_Guide/JavaScript_Overview", "ko": "ko/Core_JavaScript_1.5_Guide/JavaScript_Overview", "pl": "pl/Przewodnik_po_j\u0119zyku_JavaScript_1.5/Przegl\u0105d_JavaScriptu" } ) }}
恢复到这个版本