【前端学习】—箭头函数和普通函数的区别(十四)

编程入门 行业动态 更新时间:2024-10-25 02:24:41

【前端学习】—箭头<a href=https://www.elefans.com/category/jswz/34/1771370.html style=函数和普通函数的区别(十四)"/>

【前端学习】—箭头函数和普通函数的区别(十四)

【前端学习】—箭头函数和普通函数的区别(十四)

一、箭头函数和普通函数的区别

 const obj={fullName:'zz',sayName(){console.log(`this.fullName`,this.fullName)//zz}}obj.sayName();
 const obj={fullName:'zz',sayName:()=>{console.log(`this.fullName`,this.fullName)//undefined}}obj.sayName();
function sayName(){console.log(`this.fullName`,this.fullName)
}const obj={fullName:'freemen'
}
sayName.call(obj);//this.fullName freemen

const sayName=(...args)=>{console.log(`args`,args)
}
sayName('a','b');//['a', 'b']
function Person(){this.name='cai';const target=new.target;console.log(`target`,target)
}
const obj=new Person;
console.log(`obj`,obj);
//箭头函数不允许使用new.targetconst Person=()=>{this.name='cai';const target=new.target;console.log(`target`,target)
}
const obj=new Person;
console.log(`obj`,obj);//Uncaught SyntaxError: new.target expression is not allowed here

二、ES6中哪个方法可以实现数组去重

es6中实现数组去重的方法是Array.from配合new Set

const array=[1,2,3,4,2,1,2];
//const result=new Set(array);//输出的结果是对象我们使用Array.from方法转化为数组const result=Array.from(new Set(array));
console.log(result);//[ 1, 2, 3, 4 ]

更多推荐

【前端学习】—箭头函数和普通函数的区别(十四)

本文发布于:2023-12-05 15:52:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1664619.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   箭头   区别   十四

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!