ECMAScript is an object-oriented programming language for performing computations and manipulating computational objects within a host environment. react
ECMAScript是一门面向对象的(脚本)编程语言,它在特定的宿主环境中执行计算和处理可计算对象。程序员
这里有几个比较重要的点:web
下面咱们来根据上面的关键词依次作出解释。express
ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of communicating objects.编程
ECMAScript是基于对象的:基础语言功能以及宿主设施以对象的方式提供,而且,ECMAScript程序自己就是可交互的对象集合。windows
A scripting language is a programming language that is used to manipulate, customize, and automate the facilities of an existing system. In such systems, useful functionality is already available through a user interface, and the scripting language is a mechanism for exposing that functionality to program control. In this way, the existing system is said to provide a host environment of objects and facilities, which completes the capabilities of the scripting language.数组
脚本语言是在已有系统中操做、自定义和自动化基础设施的编程语言。在这个系统中,可用功能以用户接口的方式提供给用户,脚本语言自己就是暴露接口来控制程序的一种机制。就这样,已有系统被称为提供对象以及其余基础设施的宿主环境,以此完成脚本语言的功能。浏览器
ECMAScript最初是被设计为Web脚本语言的,它能够在浏览器中操做Web页面,也能够做为Web客户端-服务器架构中的一部分执行服务端计算。安全
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.bash
web浏览器提供了ECMAScript执行客户端计算的宿主环境,包括:instance, objects that represent windows, menus, pop-ups, dialog boxes, text areas, anchors, frames, history, cookies, 以及input/output等对象。另外,宿主环境提供了一种将代码与事件绑定的机制,例如改变焦点、页面和图片的加载卸载报错终止、选择提交以及鼠标动做等。脚本代码能够出如今HTML中,所以,咱们所看到的网页实际上是用户接口元素与文本图片等的结合体。脚本代码能够响应用户行为,而且这个过程不须要主程序参与。
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.
Web服务器提供了一个不一样的宿主环境用来进行服务端计算,它包括如下对象:representing requests, clients 和 files;另外,它还提供了一种数据加锁和数据分享的机制。
在ECMAScript中,对象(Object)是零个或多个属性(property)的集合,每一个属性有描述其使用方式的特性(attributes)。咱们能够把属性看作是一个容器,能够盛放其余的对象、原始值以及函数。
ECMAScript defines a collection of built-in objects that round out the definition of ECMAScript entities.
ECMAScript定义了一系列的内置对象(build-in objects),他们构成了ECMAScript定义的实体。
这些内置对象包括:
ECMAScript对象的继承并非像Java、C++同样基于类的继承。对象能够经过字面量符号(literal notation)或者构造器(constructor)建立。构造器是一个函数对象,每一个构造器都拥有一个prototype的属性,该属性用于实现基于原型的继承以及属性共享。构造器使用new操做符来完成对象建立工做。
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.
每个被构造器(constructorA)生成的对象A都会存在一个指向 constructorA.prototype 的隐式引用(ECMAScript标准中为[[ prototype ]],该引用在Chrome浏览器中对应的实现为__proto__),即A.__proto__指向constructorA.prototype;另外,constructorA.prototype自己也是对象(即对象B),可能由另外的构造器(constructorB)建立,即B.__proto__指向constructorB.prototype(对象O);以此类推,直到某个对象的__proto__指向空指针null,这就构成了咱们所说的原型链。
以上过程的示意图以下:
ECMAScript从设计之初就以简单易用为理念,吸引了很大一批开发者。宽松的语言限制对入门ECMAScript是有好处的,但对于高级ECMAScript程序员来讲,这无疑是“灾难”。
ECMAScript意识到了这样的需求,而且以严格模式的方式让开发者能够更好地限制语言层面的一些奇怪的特性。
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.
一些开发者会更关注安全问题,为了达到这一目的,他们一般会避免使用一些容易出错的特性,加强代码的错误检测等等。为了支持这一需求,ECMAScript在语言中定义了一种“严格变体”(严格模式)。这种严格模式除去了一些特定的语法特征,而且修正了一些语义细节。另外,严格模式相比于非严格模式会在某些特定状况下抛出错误而不是静默失败。
MDN中对严格模式有很详细的使用说明:MDN严格模式
数据类型
Undefined Null Boolean Number Symbol String 六种数据类型的取值。
A primitive value is a datum that is represented directly at the lowest level of the language implementation.
原始值是最基本的数据,是语言最底层的实现。
Object类型的成员
An object is a collection of properties and has a single prototype object. The prototype may be the null value.
构造器是建立和初始化对象的 函数对象。
The value of a constructor’s prototype property is a prototype object that is used to implement inheritance and shared properties.
原型可让对象之间进行属性共享。
When a constructor creates an object, that object implicitly references the constructor’s prototype property for the purpose of resolving property references. The constructor’s prototype property can be referenced by the program expression constructor.prototype, and properties added to an object’s prototype are shared, through inheritance, by all objects sharing the prototype. Alternatively, a new object may be created with an explicitly specified prototype by using the Object.create built-in function.
做为普通对象,它必须拥有全部对象都支持的一些关键内部方法,而且支持其默认行为。
外来对象有一些关键的内部方法的表现可能与默认行为会存在不一样。
标准对象的语义符合ECMAScript规范
内置对象是由"ECMAScript实现"(这里能够理解为宿主对象或者为JS引擎)指定和提供的对象。
Standard built-in objects are defined in this specification. An ECMAScript implementation may specify and supply additional kinds of built-in objects. A built-in constructor is a built-in object that is also a constructor.
标准内置对象是由ECMAScript规范所定义的。一个ECMAScript的实现可能会提供额外的内置对象。内置构造器是一个内置函数对象。
总结:
undefined 是一个原始类型值,当一个变量声明后未赋值,它的取值是undefined
仅有一个undefined值得数据类型
null是一个原始类型值,它表明一个空对象指针。
仅有一个null值得数据类型
Boolean类型的数据成员
There are only two Boolean values, true and false
复制代码
包含两个原始值 true false 的数据类型
标准内置构造器 Boolean 的实例对象。
A Boolean object is created by using the Boolean constructor in a new expression, supplying a Boolean value as an argument. The resulting object has an internal slot whose value is the Boolean value. A Boolean object can be coerced to a Boolean value.
字符串值是一种原始值,它是一种由零个或多个16 bit无符号整数组成的有限的有序序列。
A String value is a member of the String type. Each integer value in the sequence usually represents a single 16-bit unit of UTF-16 text. However, ECMAScript does not place any restrictions or requirements on the values except that they must be 16-bit unsigned integers.
字符串值是字符串数据类型的组成成员。序列中的每个整数值一般表明一个16-bit的UTF-16字符集单元。然而,ECMAScript并不强制或要求它们必定是 16-bit 无符号整数。
字符串数据类型是全部字符串取值的集合。
字符串对象是标准内置构造器String的实例。
一种原始值数据,它的表现与IEEE 754-2008数值规范中的双精度64-bit数值一致。
A Number value is a member of the Number type and is a direct representation of a number.
数字值是数字数据类型中 全部的数字
数字数据类型 包括 数字值 NaN(Not-a-Number) +Infinate -Infinate
数字对象是标准内置构造器Number的实例。
A Number object is created by using the Number constructor in a new expression, supplying a number value as an argument. The resulting object has an internal slot whose value is the number value. A Number object can be coerced to a number value by calling the Number constructor as a function (20.1.1.1).
IEEE-754-2008规范中的 “Not-a-Number”
正无穷
一种原始值,它用于对象 非字符串类型的惟一键 (key)
全部符合值的集合
标准内置构造器 Symbol 的实例。
能够做为子程序调用的对象类型成员。
In addition to its properties, a function contains executable code and state that determine how it behaves when invoked. A function’s code may or may not be written in ECMAScript.
除了包含属性外,一个函数还包括了可执行代码和与调用行为相关的状态。函数代码能够不写(空函数)。
内置函数 例如parseInt Math.exp等
属性是对象的一部分,它是一个关联的键(String value 或者 Symbol value)值对组合
对象属性是函数,此时称这个属性为方法
内置方法:该方法是一个内置函数
特性:它是一些内部值,定义了属性的特征。
一个对象自身所包含的属性 而非从原型链中继承的属性
继承属性:从原型链中取得的属性