《ES6 标准入门(第3版)》读书笔记(随时更新)

来源:互联网 发布:网络硬盘哪个好 编辑:程序博客网 时间:2024/05/29 16:02

   ES6语法已经被广泛应用,因此有必要跟着阮一峰大神的书去系统地学习一遍了。把自己学习过程中的心得笔记难点记录下来,欢迎大家随时交流探讨。


ES6简介

1. ES6 的第一个版本,就这样在2015年6月发布了,正式名称就是《ECMAScript 2015标准》(简称 ES2015)。ES6 既是一个历史名词,也是一个泛指,含义是5.1版以后的 JavaScript 的下一代标准,涵盖了ES2015、ES2016、ES2017等等,而ES2015 则是正式名称,特指该年发布的正式版本的语言标准。本书中提到 ES6 的地方,一般是指 ES2015 标准,但有时也是泛指“下一代 JavaScript 语言”。

2.查看node环境对ES6的支持:

$ npm install -g es-checker$ es-checker

C:\>es-checker


ECMAScript 6 Feature Detection (v1.4.1)


Variables
  √ let and const
  √ TDZ error for too-early access of let or const declarations
  √ Redefinition of const declarations not allowed
  √ destructuring assignments/declarations for arrays and objects
  √ ... operator


Data Types
  √ For...of loop
  √ Map, Set, WeakMap, WeakSet
  √ Symbol
  √ Symbols cannot be implicitly coerced


Number
  √ Octal (e.g. 0o1 ) and binary (e.g. 0b10 ) literal forms
  √ Old octal literal invalid now (e.g. 01 )
  √ Static functions added to Math (e.g. Math.hypot(), Math.acosh(), Math.imul(
) )
  √ Static functions added to Number (Number.isNaN(), Number.isInteger() )


String
  √ Methods added to String.prototype (String.prototype.includes(), String.prot
otype.repeat() )
  √ Unicode code-point escape form in string literals (e.g. \u{20BB7} )
  √ Unicode code-point escape form in identifier names (e.g. var \u{20BB7} = 42
; )
  √ Unicode code-point escape form in regular expressions (e.g. var regexp = /\
u{20BB7}/u; )
  √ y flag for sticky regular expressions (e.g. /b/y )
  √ Template String Literals


Function
  √ arrow function
  √ default function parameter values
  √ destructuring for function parameters
  √ Inferences for function name property for anonymous functions
  × Tail-call optimization for function calls and recursion


Array
  × Methods added to Array.prototype ([].fill(), [].find(), [].findIndex(), [].
entries(), [].keys(), [].values() )
  √ Static functions added to Array (Array.from(), Array.of() )
  √ TypedArrays like Uint8Array, ArrayBuffer, Int8Array(), Int32Array(), Float6
4Array()
  √ Some Array methods (e.g. Int8Array.prototype.slice(), Int8Array.prototype.j
oin(), Int8Array.prototype.forEach() ) added to the TypedArray prototypes
  √ Some Array statics (e.g. Uint32Array.from(), Uint32Array.of() ) added to th
e TypedArray constructors


Object
  √ __proto__ in object literal definition sets [[Prototype]] link
  √ Static functions added to Object (Object.getOwnPropertySymbols(), Object.as
sign() )
  √ Object Literal Computed Property
  √ Object Literal Property Shorthands
  √ Proxies
  √ Reflect


Generator and Promise
  √ Generator function
  √ Promises


Class
  √ Class
  √ super allowed in object methods
  √ class ABC extends Array { .. }


Module
  × Module export command
  × Module import command




=========================================
Passes 38 feature Detections
Your runtime supports 90% of ECMAScript 6
=========================================
 
 

3.let声明的变量只在它所在的代码块有效;不存在变量提升;

暂时性死区:本质就是,只要一进入当前作用域,所要使用的变量就已经存在了,但是不可获取,只有等到声明变量的那一行代码出现,才可以获取和使用该变量;

不允许重复声明:let不允许在相同作用域内,重复声明同一个变量。

4.let实际上为 JavaScript 新增了块级作用域。ES6 允许块级作用域的任意嵌套。

5.do 表达式:现在有一个提案,使得块级作用域可以变为表达式,也就是说可以返回值,办法就是在块级作用域之前加上do,使它变为do表达式。

6.const 命令:const声明一个只读的常量。一旦声明,常量的值就不能改变。const声明的变量不得改变值,这意味着,const一旦声明变量,就必须立即初始化,不能留到以后赋值。const命令声明的常量也是不提升,同样存在暂时性死区,只能在声明的位置后面使用。const实际上保证的,并不是变量的值不得改动,而是变量指向的那个内存地址不得改动。




原创粉丝点击