通過使用es6功能是破壞,在對象,如果我們做了一些方法,所以我們可以提取該方法也作爲屬性,我們可以,因爲我嘗試這樣做,請看看上面的代碼ES6功能解構
let person = {
name: "Ravi",
favGames: ["cricket", "Badminton", "Tennis"],
displayFavGames() {
this.favGames.forEach(game => {
console.log("My gave game " + game)
})
}
}
person.displayFavGames();
let displayData = ({
name,
favGames,
displayFavGames
}) => {
return `My name is ${name} and my cofavourite games is
${displayFavGames}`;
}
console.log(displayData(person));
我不明白你在尋求什麼幫助。請告訴我們確切的問題是什麼。 – jfriend00
'displayFavGames'是一個函數。你不調用函數,你只是將函數定義插入到模板字符串中。 – Barmar
我看到一個聲明和代碼,但沒有問題。 – apokryfos