【发布时间】:2018-10-30 18:47:26
【问题描述】:
我是 JS 新手。如果我添加这样的分号${this.name} is friends with ${el};我会收到一个错误“参数列表后未捕获的语法错误:缺少)”。我可以知道为什么吗?由于在 ES5 中,我可以使用分号,例如 return this.name + ' is friends with ' +el;
非常感谢!
function Person(name) {
this.name = name;
}
ES6
Person.prototype.myFriends5 = function(friends) {
var arr = friends.map((el) =>
`${this.name} is friends with ${el}`
);
console.log(arr);
}
var friends = ['Bob', 'Jane', 'Mark'];
new Person('John').myFriends5(friends);
【问题讨论】:
标签: javascript ecmascript-6 arrow-functions