In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces what is the difference between es6 and es5, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
The difference between es6 and es5: 1, es6 added arrow function, es5 did not; 2, ES6 added block-level scope, es5 did not; 3, ES6 introduced the concept of Class, no longer use prototype chain to achieve inheritance like ES5; 4, ES6 can set default function parameters, and so on.
The operating environment of this tutorial: windows7 system, ECMAScript 5&&ECMAScript version 6, Dell G3 computer.
Compared with ES5, ES6 has added a lot of things, such as:
First, add arrow function
The problem solved by the arrow function
The writing method is simplified. The arrow function is suitable for situations where there is only one line in the function body; when there are multiple lines, ordinary functions can be used to increase readability. Less code, clear structure
This is clearly defined. The this of traditional JS is determined at run time, not at definition time, while the this of arrow functions is determined at definition time and cannot be changed or modified by methods such as call,apply,bind. It is clear who the runtime this points to, and there is no need for the runtime to judge the this pointing to.
Note: the arrow function does not have its own this, and its this is the outer this, pointing to the this of the last function that is not the arrow function. Because of the mechanism of js, it points to the scope of a function that is not an arrow function.
The difference between Arrow function and ordinary function
The declaration of ordinary function is the highest in variable promotion, and the arrow function has no function promotion.
The arrow function does not have this, and the this object inside the function body is the object in which it is defined, not the object in use.
The arrow function does not have an arguments object, which does not exist in the function body. If you want to use it, you can use the rest parameter.
Arrow function cannot be used as a constructor, cannot be new, there is no property
Call and apply methods only have parameters and have no scope
The yield command cannot be used, so the arrow function cannot do the Generator function
Block-level scope
The let command in ES6 declares variables, and the usage is similar to var, but let adds a block-level scope to JavaScript, there is no block-level scope in ES5, and var has the concept of variable promotion, but in let, the variables used must be declared; const declares constants
Structural assignment of variables in ES6, for example: var [a _ b _ c] = _
III. Class inheritance
Instead of using prototype chains to implement inheritance like ES5, ES6 introduces the concept of Class, which sounds a bit like the syntax of object-oriented programming in Java, but the two are different.
4. Set default function parameters
The default function parameters can be set in ES6, such as function A (x _ ref _ y _ 9) {}
5. Promise
Background of promise: solving callback hell problem, handling asynchronous requests
Promise usage: chained calls, success and failure callbacks, three states, triggered when the pending state changes. Once the state changes, it will not change again.
VI. Template string
VII. Assignment structure
Thank you for reading this article carefully. I hope the article "what's the difference between es6 and es5" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.