当前位置:网站首页>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();边栏推荐
- 软件测试基本流程有哪些?权威的第三方软件检测机构推荐
- 后台图库上传功能
- 那些年我写过的语言
- EMQX Newsletter 2022-07|EMQX 5.0 正式发布、EMQX Cloud 新增 2 个数据库集成
- Statistical machine learning 】 【 linear regression model
- 边缘盒子+时序数据库,美的数字化平台 iBuilding 背后的技术选型
- 第三方验收测试报告有什么作用?如何获取权威软件测试报告?
- JMeter笔记5 |Badboy使用和录制
- leetcode 231. 2 的幂
- Kubernetes资源编排系列之三: Kustomize篇 作者 艄公(杨京华) 雪尧(郭耀星)
猜你喜欢

机器学习中专业术语的个人理解与总结(纯小白)

力扣203-移除链表元素——链表

高并发,你真的理解透彻了吗?

Detailed demonstration pytorch framework implementations old photo repair (GPU)

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

详解AST抽象语法树
[email protected] 594/[email prote"/>RNA核糖核酸修饰Alexa 568/[email protected] 594/[email prote

一种能有效缓解环境噪声对音频质量干扰的方案

RNA核糖核酸修饰荧光染料|HiLyte Fluor 488/555/594/647/680/750标记RNA核糖核酸

宁德时代2号人物黄世霖辞任副董事长:身价1370亿
随机推荐
Advantages and Disadvantages of Blind and Buried Via PCB Stacked Via Design
622 设计循环队列——Leetcode天天刷【循环队列,数组模拟,双指针】(2022.8.2)
李沐动手学深度学习V2-自然语言推断与数据集SNLI和代码实现
云服务器如何安全使用本地的AD/LDAP?
Edge box + time series database, technology selection behind Midea's digital platform iBuilding
leetcode 1837. The sum of the digits in the K-base representation
glusterfs 搭建使用
ES6简介及let、var、const区别
ThreadLocal详解
(十六)51单片机——红外遥控
亚马逊云科技 Build On 2022 - AIot 第二季物联网专场实验心得
剑指 Offer II 044. 二叉树每层的最大值-dfs法
leetcode 072. Finding Square Roots
边缘盒子+时序数据库,美的数字化平台 iBuilding 背后的技术选型
【HiFlow】经常忘记签到怎么办?使用腾讯云场景连接器每天提醒你。
abs()、fabs() 和 labs() 的区别
使用 ReportLab 绘制 PDF
转运RNA(tRNA)甲基化修饰7-甲基胞嘧啶(m7C)|tRNA-m7G
力扣206-反转链表——链表
tRNA-m5C转运RNA(tRNA)修饰5-甲基胞嘧啶(m5C)|tRNA修饰m1Am2A (2-methyladenosine)