Open iidear opened 5 years ago
ECMAScript 最早出现在网景的 Navigator 2.0 浏览器中,由 Brendan Eich 发明。
几乎所有浏览器都支持,引入了以下功能
将浏览器的普遍实现定义为规范,增加的以下新特性
修订错误
Scope: This Standard defines the ECMAScript 2015 general purpose programming language.
In computer software, a general-purpose programming language is a programming language designed to be used for writing software in the widest variety of application domains (a general-purpose language). wikipedia
A domain-specific language (DSL) is a computer language specialized to a particular application domain.wikipedia
Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which may contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. A feature of objects is that an object's procedures can access and often modify the data fields of the object with which they are associated (objects have a notion of "this" or "self").wikipedia
Class-based vs prototype-based
In class-based languages the classes are defined beforehand and the objects are instantiated based on the classes. In prototype-based languages the objects are the primary entities. No classes even exist. The prototype of an object is just another object to which the object is linked. Every object has one prototype link (and only one). New objects can be created based on already existing objects chosen as their prototype.
A scripting language is a programming language that is used to manipulate, customize, and automate the facilities of an existing system.
function Person() {}
var p = new Person()
p.__proto__ === Person.prototype // true
Person.prototype.name = 'xx'
p.name // 'xx'
规范章节安排大致如下:
规范先讲了 ECMAScript 语言的数据类型(ECMAScript Language Types)
为了解释语言的语义而定义的抽象数据结构(ECMAScript Specification Types)
为了解释语言的语义而定义的抽象操作
代码解释执行过程中涉及的数据结构与方法
为实现对象的特性而定义的对象内部方法与状态
语言的词法、语法和语义
标准库。
整个规范需要来来回回读。借助xmind做笔记
读 《编译原理》 前2~3章,可以理解上下文无关语法与基础的词法分析、语法分析方法。
const PREFIX = 'hello, ';
function sayHi(name) {
console.log(PREFIX + name)
}
var name = 'world';
sayHi(name);
对于上面代码,解析为AST。AST explorer
词法环境:根据代码的词法结构生成。由一个环境记录和一个外层词法环境的引用组成。
A Lexical Environment is a specification type used to define the association of Identifiers to specific variables and functions based upon the lexical nesting structure of ECMAScript code.A Lexical Environment consists of an Environment Record and a possibly null reference to an outer Lexical Environment.
环境记录:记录了相关词法环境作用域的标识符绑定。
An Environment Record records the identifier bindings that are created within the scope of its associated Lexical Environment.
ECMAScript 是基于对象的语言。Code Realm 存放了语言的固有对象和全局环境。
Before it is evaluated, all ECMAScript code must be associated with a Realm.
执行上下文用于跟踪代码执行的运行时。执行上下文栈用于记录上下文的切换,栈顶为当先执行上下文。 一个执行上下文通常由以下几部分组成:
对于 ECMAScript 代码,执行上下文还包括:
Job 是对启动 ECMAScript 执行任务的抽象。
A Job is an abstract operation that initiates an ECMAScript computation when no other ECMAScript computation is currently in progress.
PendingJob 是对待执行 Job 的抽象。
A PendingJob is a request for the future execution of a Job.
Job Queue 是 PendingJob 的队列。
A Job Queue is a FIFO queue of PendingJob records.
ECMAScript 至少实现两种任务队列: ScriptJobs、 PromiseJobs。
http://www.ecma-international.org/ecma-262/6.0/index.html