" to be used to define functions. Compared with ordinary functions, it supports expressions and statement bodies, and the arrow function has the same relationship with the code around this Same scope."/> " to be used to define functions. Compared with ordinary functions, it supports expressions and statement bodies, and the arrow function has the same relationship with the code around this Same scope.">
Home > Article > Web Front-end > Is arrow function a new feature of es6?
The arrow function is a new function of es6; the arrow function is a new function in es6, which allows the use of arrow "=>" to define functions. Compared with ordinary functions, it supports expressions and statement bodies, and arrows Functions have the same scope as the code surrounding this.
The operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.
The ES6 standard adds a new function: Arrow Function, which allows the use of arrow => to define functions.
Compared with ordinary functions, it is similar in syntax to C# and related functions in Java 8, supporting expressions and statement bodies.
Unlike ordinary functions, arrow functions have the same scope as the code around this. Arrow functions have the following characteristics:
#1. The function keyword is not required to create a function.
2. Omit the return keyword.
3. This always points to the this value in the scope where the function is declared (that is, the arrow function does not have its own this at all, but refers to the outer this).
Use ES6 arrow function syntax to define a function, delete the "function" keyword and function name of the original function, and use "=>" to connect the parameter list and function body.
The role of arrow function
// 1、使表达更加简洁 const isEven = n => n % 2 === 0; const square = n => n * n; // 2、简化回调函数 // 普通函数写法 [1,2,3].map(function (x) { return x * x; }); // 箭头函数写法 [1,2,3].map(x => x * x);
es5 writing method:
##Arrow function:[Related recommendations:
javascript video tutorial, web front-end]
The above is the detailed content of Is arrow function a new feature of es6?. For more information, please follow other related articles on the PHP Chinese website!