Home Article Practice 箭头函数

箭头函数

2019-07-10 17:51  views:1712  source:小键人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());



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

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