当前位置:网站首页>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();边栏推荐
猜你喜欢

力扣707-设计链表——链表

头条服务端一面经典10道面试题解析

List类的超详细解析!(超2w+字)

EasyCVR平台海康摄像头语音对讲功能配置的3个注意事项

Likou 59 - Spiral Matrix II - Boundary Judgment

危化企业双重预防机制数字化建设进入全面实施阶段

tRNA甲基化偶联3-甲基胞嘧啶(m3C)|tRNA-m3C (3-methylcy- tidine)

Hinton2022年RobotBrains访谈记录

Detailed demonstration pytorch framework implementations old photo repair (GPU)

力扣203-移除链表元素——链表
随机推荐
云服务器如何安全使用本地的AD/LDAP?
2022 年值得尝试的 7 个 MQTT 客户端工具
xss.haozi练习通关详解
转运RNA(tRNA)甲基化修饰7-甲基胞嘧啶(m7C)|tRNA-m7G
面试官:为什么 0.1 + 0.2 == 0.300000004?
node版本切换工具NVM以及npm源管理器nrm
高位套牢机构,用友网络的信任危机是如何产生的?
C中的数据存储
头条服务端一面经典10道面试题解析
tRNA甲基化偶联3-甲基胞嘧啶(m3C)|tRNA-m3C (3-methylcy- tidine)
CLIP论文解读
Go语言为任意类型添加方法
深入理解JVM-内存结构
Matlab paper illustration drawing template No. 42 - bubble matrix diagram (correlation coefficient matrix diagram)
alicloud3搭建wordpress
YARN功能介绍、交互流程及调度策略
charles配置客户端请求全部不走缓存
双线性插值公式推导及Matlab实现
Hinton2022年RobotBrains访谈记录
ARMuseum