ECMAScript Study Notes

Source: Internet
Author: User

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?
    1. Inner variables may overwrite outer variables
    2. 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:

    1. Value of the interchange variable
    2. Returning multiple values from a function
    3. Definition of function parameters
    4. Extracting JSON data
    5. Default values for function parameters
    6. Traverse the map structure
    7. 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:

  
 
  1. function Fibonacci(n) {
  2. if (n <= 1) {
  3. return 1;
  4. };
  5. return Fibonacci(n - 1) + Fibonacci(n - 2);
  6. }
  7. console.log(Fibonacci(10));
  8. function FibonacciTailCall(n) {
  9. var AC1 = arguments length <= 1 | | arguments [ 1 ] === undefined 1 : arguments [ 1 ;
  10. var AC2 = arguments length <= 2 | | arguments [ 2 ] === undefined 1 : arguments [ 2 ;
  11. if (n <= 1) {
  12. return ac2;
  13. }
  14. return FibonacciTailCall(n - 1, ac2, ac1 + ac2);
  15. }
  16. 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...inLoops: 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.

    1. The proto property of the subclass, which represents the inheritance of the constructor, always points to the parent class.
    2. 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.
  
 
  1. class A {
  2. }
  3. class B extends A {
  4. }
  5. B.__proto__ === A // true
  6. B.prototype.__proto__ === A.prototype // true


From for notes (Wiz)

ECMAScript Learning Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.