当前位置:网站首页>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
- 在对象上定义函数
- 在原型上定义函数
- 动态上下文中的回调函数
- 构造函数中
- 太简短的(难以理解)函数
边栏推荐
- How do we connect to WiFi?
- Ora-00059 exceeds DB_ Files limit
- Drink at night, 50 classic SQL questions, really fragrant~
- New feature in ES6 -- arrow function
- Q1营收超预期,满帮为何赢得逆风增长?
- Four data-driven behaviors of integral system
- Touch事件的tap,longtap封装--来自小野
- ESP8266_GET请求天气预报、json解析
- Opencv image basic operation (IV) -- image feature extraction (corner detection)
- 不同CV任务的标注类型
猜你喜欢

How do online app stores of laundry chain stores do?

Q1营收超华尔街预期,挚文集团的价值等待回归

全局池化–Pytorch

LeetCode刷题 —— 手撕二叉树

What are the application fields of MAG gear pump? To sum up

帝国CMS仿《游戏鸟》模板源码/92kaifa版大型手机游戏门户网站模板

The difference and relation between machine learning and statistics

Secret behind the chart | explanation of technical indicators: tangqi'an channel

BeanFactoryPostProcessor 与BeanPostProcessor的区别

Oracle DG physical standby database uses alias data file to change path to OMF path
随机推荐
图片规则翻页
赛灵思引脚约束文件 .xdc
Oracle 11g RAC disk group has space and cannot add data files?
Vk2c22a/b anti-interference series electric meter, water meter segment code LCD driver chip data (customized dice/cog)
帝国CMS仿《手艺活》DIY手工制作网源码/92kaifa仿手艺活自适应手机版模板
ESP8266_接入百度物联网核心套件、使用MQTT协议通信
P4147 "jade toad Palace"
ES6新增特性--箭头函数
[image denoising] image denoising based on median + wavelet + Wiener + filter, including Matlab source code
Events in JS
FPGA基础架构【参考ug998】
【Objective-C】动态创建控件
面试常问:rem布局,flex布局等
【bert】:在训练bert 语义相似的任务时,last ave state 的计算
一万字彻底学会堆和二叉树
宜居行星
Before applying data warehouse ODBC, you need to understand these problems first
Simple recommendation based on Euclidean distance
Slice of go language foundation
RSA签名问题