diff --git a/translated/issues-5.html b/translated/issues-5.html index 1d38a58d0b..a7f1d77c69 100644 --- a/translated/issues-5.html +++ b/translated/issues-5.html @@ -1,40 +1,40 @@ -

Web Scripting

-

A web browser provides an ECMAScript host environment for client-side computation including, for instance, objects that represent windows, menus, pop-ups, dialog boxes, text areas, anchors, frames, history, cookies, and input/output. Further, the host environment provides a means to attach scripting code to events such as change of focus, page and image loading, unloading, error and abort, selection, form submission, and mouse actions. Scripting code appears within the HTML and the displayed page is a combination of user interface elements and fixed and computed text and images. The scripting code is reactive to user interaction, and there is no need for a main program.

-

A web server provides a different host environment for server-side computation including objects representing requests, clients, and files; and mechanisms to lock and share data. By using browser-side and server-side scripting together, it is possible to distribute computation between the client and server while providing a customized user interface for a Web-based application.

-

Each Web browser and server that supports ECMAScript supplies its own host environment, completing the ECMAScript execution environment.

+

Web 脚本

+

web 浏览器提供用于客户端计算的 ECMAScript 宿主环境,包括如代表窗口,菜单,弹出窗口,对话框,文本域,锚点,框架,历史记录,cookies以及输入/输出的实例对象。此外,宿主环境还提供了脚本代码处理如焦点改变、页面和图片的加载、卸载、错误和中断,选择,表单提交和鼠标交互等等事件的能力。通过 HTML 中的脚本代码组合用户接口元素,固定及计算文本,图片来显示页面。脚本代码不需要一个主程序即可对用户交互进行响应。

+

WEB 服务器提供一个不同于客户端的如代表请求,客户端,文件等的对象,以及数据锁定和分享的机制。为基于 Web 的应用程序提供一个定制的用户界面,通过浏览器端脚本及服务端脚本的配合使用,可以在客户端和服务端之间进行分布式计算。

+

支持 ECMAScript 的 WEB 浏览器和服务器都将它们自身的宿主环境作为 ECMAScript 的补充,以使得 ECMAScript 的执行环境变得完整。

-

ECMAScript Overview

-

The following is an informal overview of ECMAScript—not all parts of the language are described. This overview is not part of the standard proper.

-

ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of communicating objects. In ECMAScript, an object is a collection of zero or more properties each with attributes that determine how each property can be used—for example, when the Writable attribute for a property is set to *false*, any attempt by executed ECMAScript code to assign a different value to the property fails. Properties are containers that hold other objects, primitive values, or functions. A primitive value is a member of one of the following built-in types: Undefined, Null, Boolean, Number, String, and Symbol; an object is a member of the built-in type Object; and a function is a callable object. A function that is associated with an object via a property is called a method.

-

ECMAScript defines a collection of built-in objects that round out the definition of ECMAScript entities. These built-in objects include the global object; objects that are fundamental to the runtime semantics of the language including `Object`, `Function`, `Boolean`, `Symbol`, and various `Error` objects; objects that represent and manipulate numeric values including `Math`, `Number`, and `Date`; the text processing objects `String` and `RegExp`; objects that are indexed collections of values including `Array` and nine different kinds of Typed Arrays whose elements all have a specific numeric data representation; keyed collections including `Map` and `Set` objects; objects supporting structured data including the `JSON` object, `ArrayBuffer`, `SharedArrayBuffer`, and `DataView`; objects supporting control abstractions including generator functions and `Promise` objects; and reflection objects including `Proxy` and `Reflect`.

-

ECMAScript also defines a set of built-in operators. ECMAScript operators include various unary operations, multiplicative operators, additive operators, bitwise shift operators, relational operators, equality operators, binary bitwise operators, binary logical operators, assignment operators, and the comma operator.

-

Large ECMAScript programs are supported by modules which allow a program to be divided into multiple sequences of statements and declarations. Each module explicitly identifies declarations it uses that need to be provided by other modules and which of its declarations are available for use by other modules.

-

ECMAScript syntax intentionally resembles Java syntax. ECMAScript syntax is relaxed to enable it to serve as an easy-to-use scripting language. For example, a variable is not required to have its type declared nor are types associated with properties, and defined functions are not required to have their declarations appear textually before calls to them.

+

ECMAScript 概述

+

以下是 ECMAScript— 的非正式概述 —— 描述的只是该语言的一部分。这个概述不是标准的一部分。

+

ECMAScript 是基于对象的:基础语言以及主要能力都是通过对象提供,一个 ECMAScript 程序是一组可通信对象。在 ECMAScript 中,一个对象是零个或多个属性的的集合。每个属性都有确定其如何被使用的特性, 如当一个属性的 Writable 特性设置为 *false* 时,执行任何尝试对该属性分配不同值的的 ECMAScript 代码都将失败。属性是其他对象,原始值函数的容器。原始值是以下内置类型成员之一:Undefined, Null, Boolean, Number, String, and Symbol;一个对象是内置类型 Object 成员之一,一个函数是一个可调用对象。对象通过属性调用的函数叫做方法

+

ECMAScript 定义了一组内置对象,从而勾勒出 ECMAScript 实体的定义。这些内置对象包括全局对象;基本的语言运行时语义对象,包括 `Object`, `Function`, `Boolean`, `Symbol`,各种 `Error` 对象;代表和操作的数值对象,包括 `Math`, `Number`, `Date`;文本处理对象,`String`,`RegExp`;索引值集合的 `Array` 对象,以及九种值具有特定数字数据表示的 `Typed Array` 对象;泛型对象 `Map`, `Set`;支持结构化数据的 `JSON`, `ArrayBuffer`, `SharedArrayBuffer`,`DataView` 等对象;支持控制抽象的 generator 函数,`Promise` 对象;以及反射对象 `Proxy`,`Reflect`。

+

ECMAScript 还定义了一组内置运算符。ECMAScript 运算符包括各种一元运算,乘法运算符,加法运算符,位移运算符,关系运算符,等式运算符,二进制运算符,二进制逻辑运算符,赋值运算符和逗号运算符。

+

大型 ECMAScript 程序通过模块被支持,其允许程序可以被分化为多个语句和定义序列。每个模块明确地标识它所使用的其他模块提供的声明,哪些声明可供其他模块使用。

+

ECMAScript 语法有意地类似于 Java 语法。ECMAScript 语法是松散的,使其能够成为易于使用的脚本语言。例如,一个变量不需要声明其具体类型,也不需要与声明相关联属性类型,在调用定义的函数之前也不需要以文本方式显示的声明。

Objects

-

Even though ECMAScript includes syntax for class definitions, ECMAScript objects are not fundamentally class-based such as those in C++, Smalltalk, or Java. Instead objects may be created in various ways including via a literal notation or via constructors which create objects and then execute code that initializes all or part of them by assigning initial values to their properties. Each constructor is a function that has a property named `"prototype"` that is used to implement prototype-based inheritance and shared properties. Objects are created by using constructors in new expressions; for example, `new Date(2009,11)` creates a new Date object. Invoking a constructor without using new has consequences that depend on the constructor. For example, `Date()` produces a string representation of the current date and time rather than an object.

-

Every object created by a constructor has an implicit reference (called the object's prototype) to the value of its constructor's `"prototype"` property. Furthermore, a prototype may have a non-null implicit reference to its prototype, and so on; this is called the prototype chain. When a reference is made to a property in an object, that reference is to the property of that name in the first object in the prototype chain that contains a property of that name. In other words, first the object mentioned directly is examined for such a property; if that object contains the named property, that is the property to which the reference refers; if that object does not contain the named property, the prototype for that object is examined next; and so on.

+

尽管 ECMAScript 包含了定义类的语法,但是 ECMAScript 对象从根本上来说并不是像 C++,Smalltalk,Java 那样基于类的。相反,对象可以通过各种方式创建,包括字面符号,或通过构造器创建对象然后运行代码初始化其全部或部分属性值,为这些属性分配初始值。每个构造器是一个拥有名为 `"prototype"` 的属性的函数,此属性用于实现基于原型的继承共享属性。构造器通过 new 表达式创建对象:例如,`new Date(2009,11)` 创建一个新 Date 对象。不使用new调用一个构造器的结果由构造器本身决定。例如,`Date()`产生一个表示当前日期时间的字符串,而不是一个对象。

+

每个由构造器创建的对象,都有一个隐式引用(叫做对象的原型)链接到构造器的 `"prototype"` 属性值。再者,一个原型可能有一个非空隐式引用链接到它的原型,以此类推,这叫做原型链。当向对象的一个属性提出引用时,引用会指向原型链中包含此属性名的第一个对象的属性。换句话说,首先检查直接提及的对象的同名属性,如果对象包含同名的属性,引用即指向此属性,如果该对象不包含同名的属性,则下一步检查对象的原型;以此类推。

An image of lots of boxes and arrows. -

In a class-based object-oriented language, in general, state is carried by instances, methods are carried by classes, and inheritance is only of structure and behaviour. In ECMAScript, the state and methods are carried by objects, while structure, behaviour, and state are all inherited.

-

All objects that do not directly contain a particular property that their prototype contains share that property and its value. Figure 1 illustrates this:

-

CF is a constructor (and also an object). Five objects have been created by using `new` expressions: cf1, cf2, cf3, cf4, and cf5. Each of these objects contains properties named `q1` and `q2`. The dashed lines represent the implicit prototype relationship; so, for example, cf3's prototype is CFp. The constructor, CF, has two properties itself, named `P1` and `P2`, which are not visible to CFp, cf1, cf2, cf3, cf4, or cf5. The property named `CFP1` in CFp is shared by cf1, cf2, cf3, cf4, and cf5 (but not by CF), as are any properties found in CFp's implicit prototype chain that are not named `q1`, `q2`, or `CFP1`. Notice that there is no implicit prototype link between CF and CFp.

-

Unlike most class-based object languages, properties can be added to objects dynamically by assigning values to them. That is, constructors are not required to name or assign values to all or any of the constructed object's properties. In the above diagram, one could add a new shared property for cf1, cf2, cf3, cf4, and cf5 by assigning a new value to the property in CFp.

-

Although ECMAScript objects are not inherently class-based, it is often convenient to define class-like abstractions based upon a common pattern of constructor functions, prototype objects, and methods. The ECMAScript built-in objects themselves follow such a class-like pattern. Beginning with ECMAScript 2015, the ECMAScript language includes syntactic class definitions that permit programmers to concisely define objects that conform to the same class-like abstraction pattern used by the built-in objects.

+

一般情况下基于类的面向对象语言的实例拥有状态,类拥有方法,并且只能继承结构和行为。在 ECMAScript 中,对象拥有状态和方法,并且结构,行为,状态全都可继承。

+

所有不直接包含特定属性的对象会共享他们原型中包含的此属性及属性值。图 1 说明了这一点:

+

CF 是一个构造器(也是一个对象)。五个对象已用 `new` 表达式创建: cf1, cf2, cf3, cf4, cf5。每个对象都有名为 `q1` 和 `q2` 的属性。虚线表示隐式原型关系;例如:cf3 的原型是 CFp。构造器 CF 自己有名为 `P1` 和 `P2` 的两个属性, 这对 CFp,cf1, cf2, cf3, cf4, cf5 是不可见的。CFp 的名为 `CFP1` 的属性共享给 cf1, cf2,cf3, cf4, 以及 cf5 ( 没有CF), 以及在 CFp 的隐式原型链中找不到任何名为 `q1`, `q2`,或 `CFP1` 的属性。请注意,CFCFp 之间没有隐式原型链接。

+

不同于基于类的对象语言,属性可以通过赋值的方式动态添加给对象。也就是说,构造器并不是非要对构造的对象的全部或任何属性命名或赋值。上图中,可以给 CFp 添加新属性值的方式为 cf1, cf2, cf3, cf4,and cf5 添加一个新的共享属性。

+

尽管 ECMAScript 对象本质上不是基于类,但是基于构造函数,原型对象和方法通用模式来实现类似于类的抽象是很方便的。ECMAScript 内置对象本身即遵循这样的类模式。从 ECMAScript 2015 开始,ECMAScript 语言包含了类定义语法,允许程序员像内置对象那样简洁的定义对象。

-

The Strict Variant of ECMAScript

-

The ECMAScript Language recognizes the possibility that some users of the language may wish to restrict their usage of some features available in the language. They might do so in the interests of security, to avoid what they consider to be error-prone features, to get enhanced error checking, or for other reasons of their choosing. In support of this possibility, ECMAScript defines a strict variant of the language. The strict variant of the language excludes some specific syntactic and semantic features of the regular ECMAScript language and modifies the detailed semantics of some features. The strict variant also specifies additional error conditions that must be reported by throwing error exceptions in situations that are not specified as errors by the non-strict form of the language.

-

The strict variant of ECMAScript is commonly referred to as the strict mode of the language. Strict mode selection and use of the strict mode syntax and semantics of ECMAScript is explicitly made at the level of individual ECMAScript source text units. Because strict mode is selected at the level of a syntactic source text unit, strict mode only imposes restrictions that have local effect within such a source text unit. Strict mode does not restrict or modify any aspect of the ECMAScript semantics that must operate consistently across multiple source text units. A complete ECMAScript program may be composed of both strict mode and non-strict mode ECMAScript source text units. In this case, strict mode only applies when actually executing code that is defined within a strict mode source text unit.

-

In order to conform to this specification, an ECMAScript implementation must implement both the full unrestricted ECMAScript language and the strict variant of the ECMAScript language as defined by this specification. In addition, an implementation must support the combination of unrestricted and strict mode source text units into a single composite program.

+

ECMAScript 严格变体

+

ECMAScript 语言认识到有的开发者可能希望限制使用语言中的新特性。他们这样做可能是为了安全考虑,避免他们认为是容易出错的功能,获得增强的错误检查,或其他原因。因此,ECMAScript 中定义了语言的严格变体。语言的严格变体,排除了 ECMAScript 语言的某些特定的语法和语义特征,还修改了某些功能的详细语义。严格变体还指定了必须抛出错误异常报告的额外错误条件,即使在非严格的语言形式下这些条件不属于错误。

+

ECMAScript 的严格变体通常被称为语言的严格模式。严格模式选择和使用明确地适用于独特 ECMAScript 代码单元级别的,ECMAScript 严格模式语法和语义。由于语法代码单元级别的严格模式被选择,严格模式仅在这个代码单元内施加有局部效果的限制。严格模式不限制或修改任何层面的 ECMAScript 语义,必须一致地操作跨多个代码单元。一个 ECMAScript 程序可同时包含严格模式和非严格模式的代码单元。在这种情况下,严格的模式只适用于严格模式代码单元内实际执行的代码。

+

要符合这一规范,ECMAScript 的实现必须同时实现未限制的 ECMAScript 语言和按照这个规范定义的 ECMAScript 的严格模式变体。此外,实现还必须支持未限制的和严格模式代码单元的在同一个程序中混用。

\ No newline at end of file