Let and const commands
- The let declaration is scoped to a code block, and there is no variable promotion.
- Let does not allow the same variable to be declared repeatedly within the same scope.
- A const usage is similar to let, except that a const-declared variable is a constant.
Why do I need block-level scopes?
- Inner variables may overwrite outer variables
- The loop variable used to count is leaked as a global variable
Deconstruction assignment of an object
The default value is in effect when the property value of an object is strictly equal to undefined.
The following three deconstruction assignments must not use parentheses
- Cannot have parentheses in a variable declaration statement
- In function arguments, the pattern cannot have parentheses
- In an assignment statement, you cannot put an entire pattern, or a layer in a nested pattern, in parentheses
Cases in which parentheses can be used
- The non-modal part of an assignment statement that can use parentheses
The purpose of the variable deconstruction assignment:
- Value of the interchange variable
- Returning multiple values from a function
- Definition of function parameters
- Extracting JSON data
- Default values for function parameters
- Traverse the map structure
- Specifying methods for Input modules
Extension of a string extension function
What is tail recursion (Tail call): means that the last step of a function calls another function. function calls form a "call record" in memory, called "Call Frame", which holds information such as the location of the call and internal variables. Tail call because it is the last step of the function, so there is no need to preserve the outer function of the call frame, because the call location, internal variables and other information is no longer used, as long as the inner function directly replace the outer function of the call frame can be.
Examples of the Fibonacci series are as follows:
function Fibonacci(n) {
if (n <= 1) {
return 1;
};
return Fibonacci(n - 1) + Fibonacci(n - 2);
}
console.log(Fibonacci(10));
function FibonacciTailCall(n) {
-
var AC1 = arguments length <= 1 | | arguments [ 1 ] === undefined 1 : arguments [ 1 ;
-
var AC2 = arguments length <= 2 | | arguments [ 2 ] === undefined 1 : arguments [ 2 ;
if (n <= 1) {
return ac2;
}
return FibonacciTailCall(n - 1, ac2, ac1 + ac2);
}
console.log(FibonacciTailCall(1000));
Extension of the Object
ES6 allows the property name to be written only in the object, without writing the property value, at which point the property value equals the variable represented by the property name.
Describes the properties of an object enumerable
, becomes enumerable, or, if the property is false
, indicates that some operations ignore the current property. ES5 has three operations enmerbale
that ignore properties that are false.
for...in
Loops: Iterates through only the object itself and the inherited enumerable properties
Object.keys()
: Returns the key names of all enumerable properties of the object itself
JSON.stringify()
: Only the enumerable properties of the object itself are serialized
ES6 adds an action Object.assign()
that ignores enumerable
false
the property, only the enumerable property of the object itself.
Symbol
The object property name of ES5 is a string, which can cause conflicts of property names. If there is a mechanism to ensure that the name of each property is unique, this fundamentally prevents the violation of the attribute name, which is why ES6 introduced the symbol.
Proxy and reflect
Proxy is used to modify the default behavior of some operations, which is equivalent to making changes at the language level, so it belongs to a "meta-programming (meta programming)", which is programming language programming.
Binary arrays
Because WebGL refers to the communication interface between the browser and the video card, it needs to meet a lot of real-time data exchange, so the communication between them must be binary.
Binary arrays consist of three types of objects:
- Arraybuffer object: Represents a piece of binary data in memory that can be manipulated by "view". The view deploys an array interface, which means that the memory can be manipulated using an array of methods.
- Typearray View: Total of 9 types of views, such as Uint8array array view, Int16array array view, Float32array array view
- DataView View: You can customize a view that conforms to the format, such as the first byte is Uint8, the 23rd byte is Int16, the fourth byte is the Float32array array view, and so on.
In a nutshell, the Arraybuffer object represents the raw binary data, and the Typearray view is used to read and write binary data of simple types, and the DataView view is used to read and write complex binary data. The Arraybuffer object represents a piece of memory stored in binary data that cannot be read and written directly, read and written by the view, and the function of the view is to interpret the binary data in the specified format.
Typedarrary the constructor of an array, you can accept another Typedarray instance as a parameter. The new array is generated at this time, just copy the value of the parameter array, the corresponding underlying memory is not the same. The new array opens up a new set of memory storage data and does not establish a view on top of the original array's memory.
If you want to change the original set structure synchronously in the traversal operation, there is no direct method, but there are two kinds of iterations. One is to use the original set structure to map out a new structure, and then assign to the original set structure, the other is the use of the Array.from
method
In Tips:map, only a reference to the same object, the map structure treats it as the same key .
Class
The inheritance of ES5 is essentially the creation of the instance object of the subclass, and then the method of the parent class is added to this above (parent.apply (this)). The inheritance mechanism of ES6 is different in nature, which is to create the instance object of the parent class first (so the Super method must be called first), and then modify this with the subclass constructor.
Class as the syntactic sugar of the constructor, with both the prototype attribute and the proto attribute, so there are two inheritance chains.
- The proto property of the subclass, which represents the inheritance of the constructor, always points to the parent class.
- The proto property of the subclass prototype property, which represents the inheritance of the method, always points to the prototype property of the parent class.
class A {
}
class B extends A {
}
B.__proto__ === A // true
B.prototype.__proto__ === A.prototype // true
From for notes (Wiz)
ECMAScript Learning Notes