Table of Contents
Knowledge points of es6 that are often used
When it comes to es6, let’s talk about javascript. es6 is also ES2015
When it comes to es6, compatibility comes to mind. I recommend two links for you to check out. They are still very good
https:// kangax.github.io/compat-table/es6/
http://kangax.github.io/compat-table/es2016plus/
How to use es6
You can convert es6 code into es5 code. Babel Google traceur are two transcoders. You can try them.
Babel is a widely used ES6 transcoder that can convert ES6 The code is converted to ES5 code so that it can be executed in the existing environment. You can choose the tool you are used to using Babel
The difference between var, let, and const in js
var! ! ! !
Variables defined by var can be modified. If not initialized, undefined will be output and no error will be reported.
var is divided into two types: local scope and function scope
let! ! ! !
let is a block-level scope. After the function is defined using let, it has no impact on the outside of the function.
let is a block-level scope. Unlike var, let has no prefix function and cannot be repeatedly declared
const! ! ! !
Variables defined by const cannot be modified and must be initialized.
const is a constant, cannot be changed, is generally uppercase, and is also a block-level scope. . .
es6 template string, enhanced object literal, destructuring assignment
es6 template string
Template string is a string literal that allows embedded expressions . You can use multiline strings and string interpolation functions. They were called "template strings" in previous versions of the ES2015 specification.
Enhanced objects Literal
There are two ways to output object literals: traditional '.', and array mode. However, when outputting in array mode, the square brackets must be enclosed in quotation marks
Object The literal definition method can easily handle the situation where a large number of parameters of the function need to be output in one-to-one correspondence. His solution is to pass an object into the function, and this object is defined in a literal way, and the corresponding attributes and values ​​can be used. Their relationship is clear at a glance, because a function is just a piece of code that must be called to execute
Destructuring assignment
Destructuring assignment can assign the elements of the array or the properties of the object to another variable. The definition syntax of the variable is very similar to that of an array literal or an object literal. This syntax is very concise and more intuitive and clearer than the traditional property access method
In fact, it is not appropriate to use variables to describe it, because you can deconstruct nested arrays of any depth:
You can leave the corresponding bits blank to skip certain elements in the destructured array:
es6's spread operator , arrow function, function parameters
Several functions of the expansion operator
Arrow function
Function parameters
Function parameters are divided into three types
Symbol
Symbol is a new value type added in ES6 Data represents a value that never repeats
Note that the new operator cannot be used before Symbol here
If you want to get the object symbol attribute, you need to use Object. .getOwnPropertySymbols(o).
Set and WeakSet
ES6 adds 2 new data structures (New data structures) types, Set and Map
Set and WeakSet Data structures are new to ES6.
It is very similar to an array, but the members of the Set data structure are unique.
Special note: Only one NaN can be added to Set
类似于 WeakMap,WeakSet 对象可以让你在一个集合中保存对象的弱引用,在 WeakSet 中的对象只允许出现一次:
Map和WeakMap
Map和WeakMap是ES6新增的数据结构 事实上每个对象都可以看作是一个 Map。 它们本质与对象一样,都是键值对的集合,但是他们与Object对象主要的不同是,键可以是各种类型的数值,而Object对象的键只能是字符串类型或者Symbol类型值 。Map和WeakMap是更为完善的Hash结构。
WeakMap数据结构 WeakMap结构与Map结构基本类似。 区别是它只接受对象作为键名,不接受其他类型的值作为键名。键名是对象的弱引用,当对象被回收后,WeakMap自动移除对应的键值对,WeakMap结构有助于防止内存泄漏。
由于WeakMap对象不可遍历,所以没有size属性。
Home Web Front-end JS Tutorial Summary of common knowledge points in es6

Summary of common knowledge points in es6

Jul 17, 2017 pm 03:02 PM
Knowledge points

Knowledge points of es6 that are often used

When it comes to es6, let’s talk about javascript. es6 is also ES2015
  1. 1995: JavaScript was born, and its Initially named LiveScript.

  2. 1997: ECMAScript standard established.

  3. 1999: ES3 appears, at the same time IE5 is all the rage.

  4. 2000–2005: XMLHttpRequest, also known as AJAX, is widely used in Outlook Web Access (2000), Oddpost (2002), Gmail (2004) and Google Maps (2005).

  5. 2009: ES5 comes out, (which is what most of us use now) standards like foreach, Object.keys, Object.create and JSON.

  6. 2015: ES6/ECMAScript2015 appears. In 2015, TC39, the committee responsible for developing the draft ECMAScript specification, decided to change the system for defining new standards to once a year.

  7. 2016: ES7/ECMAScript2016 appears.

  8. 2017: ES8/ECMAScript2017 appears.


https:// kangax.github.io/compat-table/es6/
http://kangax.github.io/compat-table/es2016plus/

How to use es6
You can convert es6 code into es5 code. Babel Google traceur are two transcoders. You can try them.
Babel is a widely used ES6 transcoder that can convert ES6 The code is converted to ES5 code so that it can be executed in the existing environment. You can choose the tool you are used to using Babel

The difference between var, let, and const in js
var! ! ! !
Variables defined by var can be modified. If not initialized, undefined will be output and no error will be reported.
var is divided into two types: local scope and function scope
let! ! ! !
let is a block-level scope. After the function is defined using let, it has no impact on the outside of the function.
let is a block-level scope. Unlike var, let has no prefix function and cannot be repeatedly declared
const! ! ! !
Variables defined by const cannot be modified and must be initialized.
const is a constant, cannot be changed, is generally uppercase, and is also a block-level scope. . .

es6 template string, enhanced object literal, destructuring assignment
es6 template string
Template string is a string literal that allows embedded expressions . You can use multiline strings and string interpolation functions. They were called "template strings" in previous versions of the ES2015 specification.
  1. ``Apostrophe

  2. Bind variables

  3. String supports multiple lines

  4. ...Expand operator


Enhanced objects Literal
There are two ways to output object literals: traditional '.', and array mode. However, when outputting in array mode, the square brackets must be enclosed in quotation marks
Object The literal definition method can easily handle the situation where a large number of parameters of the function need to be output in one-to-one correspondence. His solution is to pass an object into the function, and this object is defined in a literal way, and the corresponding attributes and values ​​can be used. Their relationship is clear at a glance, because a function is just a piece of code that must be called to execute
  1. Literal object properties can be abbreviated

  2. Literal object methods can The abbreviation omits the function keyword

  3. Object properties can be written as automatically calculated properties

  4. Inheritance——port——


Destructuring assignment
Destructuring assignment can assign the elements of the array or the properties of the object to another variable. The definition syntax of the variable is very similar to that of an array literal or an object literal. This syntax is very concise and more intuitive and clearer than the traditional property access method
In fact, it is not appropriate to use variables to describe it, because you can deconstruct nested arrays of any depth:
var [foo, [[bar], baz]] = [1, [[2], 3]];console.log(foo);// 1console.log(bar);// 2console.log(baz);// 3
Copy after login
You can leave the corresponding bits blank to skip certain elements in the destructured array:
var [,,third] = ["foo", "bar", "baz"];console.log(third);// "baz"
Copy after login

es6's spread operator , arrow function, function parameters
Several functions of the expansion operator
  1. Expand array

  2. Copy of array

  3. Merge of arrays

  4. Call of expansion function


Arrow function
//箭头函数 =>let jian = () => {console.log("Hello")}jian();//没有参数()=>{console.log("你好")};//有参数(name)=>{console.log(name);};//可以省略()let d = name=>{console.log(name);}d('jiang');//两个参数(name,age)=>{console.log(name,age);};//省略后的let c (a,b)=>a+b;(a,b)=>{console.log(a+b);console.log(c);
Copy after login

Function parameters
Function parameters are divided into three types
  1. Default parameters

  2. Extended parameters

  3. Remaining parameters


Symbol
Symbol is a new value type added in ES6 Data represents a value that never repeats
let m = 1;let l = 1;console.log(m==l);//打印出truelet mm = Symbol();let ll = Symbol();console.log(mm==ll);//打印出flase
Copy after login
Note that the new operator cannot be used before Symbol here
If you want to get the object symbol attribute, you need to use Object. .getOwnPropertySymbols(o).

Set and WeakSet
ES6 adds 2 new data structures (New data structures) types, Set and Map
Set and WeakSet Data structures are new to ES6.
It is very similar to an array, but the members of the Set data structure are unique.
Special note: Only one NaN can be added to Set
// Setsvar s = new Set();s.add("hello").add("goodbye").add("hello");s.size === 2;s.has("hello") === true;// Weak Setsvar ws = new WeakSet();ws.add({ data: 42 });
Copy after login
类似于 WeakMap,WeakSet 对象可以让你在一个集合中保存对象的弱引用,在 WeakSet 中的对象只允许出现一次:
var ws = new WeakSet();var obj = {};var foo = {};ws.add(window);ws.add(obj);ws.has(window); // truews.has(foo);    // false, foo 没有添加成功ws.delete(window); // 从结合中删除 window 对象ws.has(window);    // false, window 对象已经被删除
Copy after login

Map和WeakMap
Map和WeakMap是ES6新增的数据结构 事实上每个对象都可以看作是一个 Map。 它们本质与对象一样,都是键值对的集合,但是他们与Object对象主要的不同是,键可以是各种类型的数值,而Object对象的键只能是字符串类型或者Symbol类型值 。Map和WeakMap是更为完善的Hash结构。
// Mapsvar m = new Map();m.set("hello", 42);m.set(s, 34);m.get(s) == 34;// Weak Mapsvar wm = new WeakMap();wm.set(s, { extra: 42 });wm.size === undefined
Copy after login
WeakMap数据结构 WeakMap结构与Map结构基本类似。 区别是它只接受对象作为键名,不接受其他类型的值作为键名。键名是对象的弱引用,当对象被回收后,WeakMap自动移除对应的键值对,WeakMap结构有助于防止内存泄漏。
var wm = new WeakMap(); var obj = new Object(); wm.set(obj,'对象1'); obj=null; wm.get(obj);    //undefined wm.has(obj);    //false
Copy after login
由于WeakMap对象不可遍历,所以没有size属性。

关键点:ES2015=ES6
最常用的ES6特性
ES5只有全局作用域和函数作用域,没有块级作用域,这带来很多不合理的场景。let则实际上为JavaScript新增了块级作用域。用它所声明的变量,只在let命令所在的代码块内有效。
块级作用域与函数声明问题:
函数能不能在块级作用域之中声明,是一个相当令人混淆的问题。
ES6引入了块级作用域,明确允许在块级作用域之中声明函数。

注意:ES6规定,块级作用域之中,函数声明语句的行为类似于let,在块级作用域之外不可引用。

当我们使用箭头函数时,函数体内的this对象,就是定义时所在的对象,而不是使用时所在的对象。
并不是因为箭头函数内部有绑定this的机制,实际原因是箭头函数根本没有自己的this,它的this是继承外面的,因此内部的this就是外层代码块的this
5.ES6的继承机制,实质是先创造父类的实例对象this(所以必须先调用super方法),然后再用子类的构造函数修改this。
6.template string
我们要插入大段的html内容到文档中时,传统的写法非常麻烦,所以之前我们通常会引用一些模板工具库

The above is the detailed content of Summary of common knowledge points in es6. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Is JavaScript hard to learn? Is JavaScript hard to learn? Apr 03, 2025 am 12:20 AM

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

The difference in console.log output result: Why are the two calls different? The difference in console.log output result: Why are the two calls different? Apr 04, 2025 pm 05:12 PM

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

How to implement panel drag and drop adjustment function similar to VSCode in front-end development? How to implement panel drag and drop adjustment function similar to VSCode in front-end development? Apr 04, 2025 pm 02:06 PM

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...

See all articles