当前位置:网站首页>ES6 - Arrow Functions
ES6 - Arrow Functions
2022-08-03 20:14:00 【Hey………】
6. Arrow function (new syntax)
The new way to define functions in ES6
//Fixed syntax structure:() => {}Arrow functions use simplified function definition syntax
const fn = () => {console.log(123); //123}fn();Feature 1. There is only one code in the function body, and the execution result of the code is the return value, you can omit the braces (see example below):
function func(a, b){return a + b;}console.log(func(1,2)); //3//arrow function:const func = (a, b) => a + b;console.log(func(1,2)); //3Feature 2. If there is only one form parameter, you can omit the parentheses
function func(a){return a;}console.log(func(1)); //1//arrow function:const func = b => { //const func = b => b;return b;};console.log(func(2)); //2Feature 3. Arrow function does not bind this keyword, this in arrow function points to the location where function is definedContext this.
function fn(){console.log(this); //{name: 'Xiao Ming'}return() => {console.log(this); //{name: 'Xiao Ming'}}}const obj = {name: 'Xiao Ming'}const resFn = fn.call(obj);resFn();Another example:
var age = 10;var obj = {age: 20,say:() => {alert(this.age); //10//Pointing to the age object under the widget cannot generate a scope, the say method is actually defined in the global scope}}obj.say();边栏推荐
猜你喜欢

abs()、fabs() 和 labs() 的区别

边缘盒子+时序数据库,美的数字化平台 iBuilding 背后的技术选型

tRNA修饰2-甲基胞嘧啶(m2C)|tRNA修饰m2G (N2-methylguanosine)

Anaconda 虚拟环境迁移

Detailed demonstration pytorch framework implementations old photo repair (GPU)

Likou 59 - Spiral Matrix II - Boundary Judgment

Alexa染料标记RNA核糖核酸|RNA-Alexa 514|RNA-Alexa 488|RNA-Alexa 430

微导纳米IPO过会:年营收4.28亿 君联与高瓴是股东

转运RNA(tRNA)甲基化修饰7-甲基胞嘧啶(m7C)|tRNA-m7G

MySQL Basics
随机推荐
JWT详解
CLIP论文解读
php根据两点经纬度计算距离
Statistical machine learning 】 【 linear regression model
子树的大小
leetcode 16.01. Swap numbers (swap the values of 2 numbers without using temporary variables)
LeetCode 899. 有序队列
leetcode 2119. Numbers reversed twice
Detailed explanation of JWT
那些年我写过的语言
李沐动手学深度学习V2-自然语言推断与数据集SNLI和代码实现
高位套牢机构,用友网络的信任危机是如何产生的?
若依集成easyexcel实现excel表格增强
5 款漏洞扫描工具:实用、强力、全面(含开源)
面试官:为什么 0.1 + 0.2 == 0.300000004?
「学习笔记」高斯消元
【飞控开发高级教程4】疯壳·开源编队无人机-360 度翻滚
【微信小程序2】事件传参与数据同步[03]
ES6简介及let、var、const区别
PHP according to the longitude and latitude calculated distance two points