当前位置:网站首页>Es6新特性——箭头函数
Es6新特性——箭头函数
2022-06-11 09:51:00 【InfoQ】
什么是箭头函数
箭头函数书写方式
//Es5
let sum = function(a,b){
return a + b;
}
// Es6
let sum1 = (a,b) =>{
return a + b;
}
console.log(sum(1,2));//3
console.log(sum1(1,2));//3
复制代码箭头函数中的参数
function sum(){
console.log(arguments[0]);
}
sum(3);//3
let sum1 = () => {
console.log(arguments[0]);
}
sum1(3);//报错 Uncaught ReferenceError: arguments is not defined
复制代码箭头函数中的this
function o() {
this.royaltyName = 'Jackons';
// this 引用 King 的实例
setTimeout( () => console.log(this.royaltyName), 1000);
};
function j() {
this.royaltyName = 'bear';
// this 引用 window 对象
setTimeout(function () {
console.log(this.royaltyName);
}, 1000);
}
new o(); //jackson
new j(); //undefinde
- 在对象上定义函数
- 在原型上定义函数
- 动态上下文中的回调函数
- 构造函数中
- 太简短的(难以理解)函数
边栏推荐
- 外包干了四年,废了...
- What are the functions and applications of Mogg test controller
- 关于马格齿轮泵的应用领域都有哪些?总结一下
- Inductive bias的一些理解
- Finish C language
- JS foundation -- about DOM
- 「INS-30131」 安装程序验证所需的初始设置失败
- ESP8266_GET请求天气预报、json解析
- Q1 revenue exceeded expectations. Why did man Bang win headwind growth?
- What are the application fields of MAG gear pump? To sum up
猜你喜欢

我们是如何连上WiFi的?

整型提升例题

Can station B make money?

ESP8266_ SmartConfig

An error will be reported when the RAC modifies the scanip to different network segments

锐意进取,砥砺前行,JASMINER持续深耕品牌实力

Revisiting Self-Training for Few-Shot Learning of Language Model,EMNLP2021

关于马格齿轮泵的应用领域都有哪些?总结一下

Rebuilding Oracle XdB components

【Objective-C】‘NSAutoreleasePool‘ is unavailable: not available in automatic reference counting mode
随机推荐
Using exec in PHP to display errors
rac expdp导出时报错:ORA-31693、ORA-31617、ORA-19505
Servlet 的初次部署
【Objective-C】动态创建控件
赛灵思引脚约束文件 .xdc
oracle 11g rac 磁盘组有空间无法增加数据文件?
parker派克先导式电磁阀和直动式电磁阀的区别有哪些?
VK2C22A/B抗干扰系列电表,水表段码LCD液晶驱动芯片资料(可定制DICE/COG)
go连接数据库报错 wsarecv: An existing connection was forcibly closed by the remote host.
ESP8266_接入百度物联网核心套件、使用MQTT协议通信
Cisp-pte XSS Foundation
An error can't locate env pm in @INC
document对象
RAC expdp export error: ora-31693, ora-31617, ora-19505
LeetCode刷题 —— 手撕二叉树
Where is it safer to open an account for soda ash futures? How much does it cost to buy at least one hand?
面试常问:rem布局,flex布局等
Override and reload?
「INS-30131」 安装程序验证所需的初始设置失败
Project lifecycle