当前位置:网站首页>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)); //3
Feature 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)); //2
Feature 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-ATTO 390|RNA-ATTO 425|RNA-ATTO 465|RNA-ATTO 488|RNA-ATTO 495|RNA-ATTO 520近红外荧光染料标记核糖核酸RNA
- Use ControlTemplate or Style from resource file in WPF .cs and find the control
- abs()、fabs() 和 labs() 的区别
- xss.haozi练习通关详解
- 头条服务端一面经典10道面试题解析
- 力扣707-设计链表——链表
- ES6 deconstruction assignment - array object deconstruction and deconstruction
- Likou 707 - Design Linked List - Linked List
- 极验深知v2分析
- Advantages and Disadvantages of Blind and Buried Via PCB Stacked Via Design
猜你喜欢
2022 年值得尝试的 7 个 MQTT 客户端工具
Edge box + time series database, technology selection behind Midea's digital platform iBuilding
ESP8266-Arduino编程实例-WS2812驱动
codeforces:C. Maximum Subrectangle【前缀和 + 贪心 + 最小子数组和】
高并发,你真的理解透彻了吗?
RNA-ATTO 390|RNA-ATTO 425|RNA-ATTO 465|RNA-ATTO 488|RNA-ATTO 495|RNA-ATTO 520近红外荧光染料标记核糖核酸RNA
算法--交错字符串(Kotlin)
高位套牢机构,用友网络的信任危机是如何产生的?
李沐动手学深度学习V2-BERT微调和代码实现
机器学习中专业术语的个人理解与总结(纯小白)
随机推荐
List类的超详细解析!(超2w+字)
leetcode 326. 3 的幂
LeetCode 622. 设计循环队列
leetcode 剑指 Offer 15. 二进制中1的个数
Matlab paper illustration drawing template No. 42 - bubble matrix diagram (correlation coefficient matrix diagram)
Use ControlTemplate or Style from resource file in WPF .cs and find the control
使用 ReportLab 绘制 PDF
Abs (), fabs () and LABS ()
PHP according to the longitude and latitude calculated distance two points
glusterfs 搭建使用
Leetcode sword refers to Offer 15. 1 in the binary number
CLIP论文解读
YARN功能介绍、交互流程及调度策略
汉源高科8光口12电口交换机千兆8光8电12电16电网管型工业以太网交换机
化算力为战力:宁夏中卫的数字化转型启示录
RNA核糖核酸修饰荧光染料|HiLyte Fluor 488/555/594/647/680/750标记RNA核糖核酸
【飞控开发高级教程6】疯壳·开源编队无人机-AI语音控制
转运RNA(tRNA)甲基化修饰7-甲基胞嘧啶(m7C)|tRNA-m7G
ES6-箭头函数
RNA-ATTO 390|RNA-ATTO 425|RNA-ATTO 465|RNA-ATTO 488|RNA-ATTO 495|RNA-ATTO 520近红外荧光染料标记核糖核酸RNA