当前位置:网站首页>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();边栏推荐
- RNA核糖核酸修饰RNA-HiLyte FluorTM 405荧光染料|RNA-HiLyte FluorTM 405
- 微导纳米IPO过会:年营收4.28亿 君联与高瓴是股东
- abs()、fabs() 和 labs() 的区别
- 华为设备配置VRRP负载分担
- 李沐动手学深度学习V2-自然语言推断与数据集SNLI和代码实现
- 子结点的数量(2)
- Matlab paper illustration drawing template No. 42 - bubble matrix diagram (correlation coefficient matrix diagram)
- ThreadLocal详解
- 软件测试基本流程有哪些?权威的第三方软件检测机构推荐
- alicloud3搭建wordpress
猜你喜欢

(十六)51单片机——红外遥控

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

Detailed demonstration pytorch framework implementations old photo repair (GPU)

Advantages and Disadvantages of Blind and Buried Via PCB Stacked Via Design
![【微信小程序2】事件传参与数据同步[03]](/img/d9/73004e6edf800c583231a94dfbd878.png)
【微信小程序2】事件传参与数据同步[03]

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

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

宁德时代2号人物黄世霖辞任副董事长:身价1370亿

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

Go语言类型与接口的关系
随机推荐
谁的孙子最多II
Leetcode 125. Verify palindrome string
刷题错题录1-隐式转换与精度丢失
Why BI software can't handle correlation analysis
leetcode 剑指 Offer 58 - II. 左旋转字符串
【STM32】标准库-自定义BootLoader
leetcode 16. 数值的整数次方(快速幂+递归/迭代)
matplotlib画polygon, circle
List类的超详细解析!(超2w+字)
JWT详解
力扣203-移除链表元素——链表
Solidity智能合约开发 — 4.1-合约创建和函数修饰器
Go语言类型与接口的关系
自定义form表单验证
极验深知v2分析
力扣59-螺旋矩阵 II——边界判断
单调栈及其应用
Use ControlTemplate or Style from resource file in WPF .cs and find the control
xss.haozi练习通关详解
ES6 deconstruction assignment - array object deconstruction and deconstruction