首页 文章 箭头函数

箭头函数

2019-07-10 17:51  浏览数:1767  来源:小键人27611    

const double1 = function(number){
return number * 2;
}
const double2 = (number) => {
return number * 2;
}
const double3 = (number) => number * 2;
const double4 = number => number * 2;
const double5 = (number => number * 2);
const double6 = (number,number2) => number + number2;
const double = (number,number2) => {
sum = number + number2
return sum;
}
// console.log(double(20,20));
// map一个数组,让数组中的值以double形式展现
const numbers = [1,2,3];
var newNumbers = numbers.map(number => number * 2);
// console.log(newNumbers);
// 改变this指向
const team1 = {
members:["Henry","Elyse"],
teamName:"es6",
teamSummary:function(){
let self = this;
return this.members.map(function(member){
// this不知道该指向谁了
return `${member}隶属于${self.teamName}小组`;
})
}
}
const team2 = {
members:["Henry","Elyse"],
teamName:"es6",
teamSummary:function(){
return this.members.map(function(member){
// this不知道该指向谁了
return `${member}隶属于${this.teamName}小组`;
}.bind(this))
}
}
const team = {
members:["Henry","Elyse"],
teamName:"es6",
teamSummary:function(){
return this.members.map((member) => {
// this指向的就是team对象
return `${member}隶属于${this.teamName}小组`;
})
}
}
console.log(team.teamSummary());



声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)