0
点赞
收藏
分享

微信扫一扫

JS中的箭头函数=>

在js中,=>是js语法中的箭头函数,也是用来定义函数的。

箭头函数特点:

箭头函数是匿名函数,无法使用函数名进行递归调用; 箭头函数没有自己的this和arguments,它们继承自父作用域; 箭头函数不能使用new关键字调用,因为它没有自己的this对象; 箭头函数不能使用yield关键字,因为它不是生成器函数。 箭头函数代码示例:

// 定义有多个参数的箭头函数 const aa=(a,b)=>{ console.log(a+b); };//输出6 aa(1,5); const sum = (x, y) => { return x + y; }; console.log(sum(1, 2)); // 输出 3 // 定义只有一个参数的箭头函数 const square = x => x * x; console.log(square(3)); // 输出 9 // 定义只有一条语句的箭头函数 const print = message => console.log(message); print("Hello!");

举报

相关推荐

0 条评论