Reading Notes: Deep Understanding of ES6 (Appendix A)

Appendix A: Minor changes in ES6

 

Section 1 uses integers

  JavaScript uses the IEEE 754 encoding system to represent integers and floating-point numbers, which has caused a lot of confusion for developers over the years. ES6 tries to solve these problems by reducing the difficulty of identifying and using integers.

  1. Due to the different storage methods of floating-point numbers and integers, the Number.isInteger() method uses this storage difference to determine whether the value is an integer.

  2. Just adding a decimal point to the number will not make the integer a floating point number.

  3. IEEE 754 can only accurately represent integers between -2^53 and 2^53. Outside this "safe" range, multiple values ​​can be represented by reusing binary.

 

Section 2 New Math Method

  1. ES6 introduces stereotyped arrays to enhance the game and graphics experience, which allows the JavaScript engine to perform more effective mathematical calculations.

  2. ES6 adds several methods to the Math object to increase the speed of usual mathematical calculations and at the same time improve the overall progress of intensive computing applications (such as graphics programs).

  3. For the specific adding method, please refer to P.333. If your application needs to perform common operations, be sure to check the new method of the Math object (whether there is already a method you need for your calculations) before doing it.

 

Section 3 Unicode identifiers

  In ES5 and ES6, Unicode escape sequences can be used as identifiers. E.g:

 //在ES 5和6 中均合法
 var \u0061 = "abc";
 
 console.log(\u0061) // "abc"
 
 //等价于:
 console.log(a); // "abc"

  

  You can also use Unicode code point escape sequences as identifiers. E.g,

 //在ES 5和6 中均合法
 var \u{61} = "abc";
 
 console.log(\u{61}); // "abc"
 
 //等价于
 console.log(a); // "abc"

 

Section 4 Formalize the __proto__ Property

  1. __proto__ is an early implementation of Object.getPropertyOf() and Object.setPropertyOf() methods.

  2. ES6 officially added the __proto__ attribute, but in the official standard: ECMA-262 Appendix B is accompanied by a warning: unless the legacy ES code needs to be executed in a web browser or like a web browser, ES implementation is not encouraged these functions.

  3. The difference between using __proto__ and using Object.getPropertyOf() or Object.setPropertyOf() is: __proto__ can directly set the prototype of the object literal. E.g,

 let person = {
     getGreeting() {
         return "hello";
     }
 };
 
 let dog = {
     getGreeting() {
         return "woof"
     }
 };
 
 //原型是person
 let friend = {
     __proto__: person
 };
 console.log(friend.getGreeting());                         //  "hello"
 console.log(Object.getPrototypeOf(friend) === person);  //  true
 console.log(friend.__proto__ === person);                 //  true
 
 //将原型设置为dog
 friend.__proto__ = dog;
 console.log(friend.getGreeting());                        // "woof"
 console.log(friend.__proto__ === dog);                    // true
 console.log(Object.getPrototypeOf(friend) === dog);        // true

 

 

(End of this section)

Guess you like

Origin blog.csdn.net/ZxxSteven/article/details/100855359