我有一個研究項目,指出:編寫一個函數bestShow接受一個對象,並返回該對象的title屬性的值。JavaScript函數接受一個對象,並返回該對象的標題屬性的值
提示提示: console.log(bestShow({genre:'comedy',title:'Seinfeld'})); //應該打印:Seinfeld
我已經嘗試了很多不同的東西。這是一次迭代,我終於放棄了。
function bestShow(genre, title)
{
this.genre = genre;
this.title = title;
}
var show = new bestShow(‘comedy’, ‘Seinfeld’);
console.log(show.bestShow.title);
'function bestShow(obj){return obj.title}' – dfsq
提示:你的任務沒有提及使用'new'。它表示要返回傳遞給函數的對象的屬性值。 –
你可以像這樣調用'console.log(show.title);' – prasanth