This book covers ES6 with three levels of detail:
Other things to know:
I started writing this book long before there were implementations of ES6 features, which required quite a bit of research. Essential sources were:
Strict mode is switched on via the following line (which does nothing in ECMAScript versions before ES5):
If you put this line at the beginning of a file, all code in it is in strict mode. If you make this line the first line of a function, only that function is in strict mode.
Using a directive to switch on strict mode is not very user friendly and was one of the reasons why strict mode was not nearly as popular in ES5 as it should be. However, ES6 modules and classes are implicitly in strict mode. Given that most ES6 code will live in modules, strict mode becomes the de-facto default for ES6.
The term protocol has various meanings in computing. In the context of programming languages and API design, I’m using it as follows:
A protocol defines interfaces (signatures for methods and/or functions) and rules for using them.
The idea is to specify how a service is to be performed. Then anyone can perform the service and anyone can request it and they are guaranteed to work together well.
Note that the definition given here is different from viewing a protocol as an interface (as, for example, Objective C does), because this definition includes rules.
Given a method call
obj is the receiver of the method call and accessible via
this inside the method.
The (type) signature of a function describes how the function is to be called, what its inputs and its output are. I’m using the syntax established by Microsoft TypeScript and Facebook Flow in this book. An example of a signature:
You can see that
parseInt() expects a string and a number and returns a number. If the type of a parameter is clear, I often omit the type annotation.
The ES6 language specification uses internal slots to store internal data. In the spec, internal slots are accessed as if they were properties whose names are in square brackets:
Two things differentiate them from properties:
Object.getPrototypeOf()to do so.
The ECMAScript spec uses a data structure called environment to store the variables of a scope. An environment is basically a dictionary that maps variable names to values. A binding is an entry in an environment, storage space for a variable.
Destructive operations (methods, functions) modify their parameters or their receivers. For example,
push() modifies its receiver
concat() creates a new Array and does not change its receiver
The API of a class
C is usually documented as follows:
String: its members are objects, instances of
string: its members are primitive values, strings.
Several repositories on GitHub contain code shown in this book:
Sidebars are boxes of text marked with icons. They complement the normal content.
Occasionally, I refer to (publicly available) external material via footnotes. Two sources are marked with a prefix in square brackets: