2016-03-06 134 views
0

我正在嘗試使用typescript的類方法。這個對我有用。但我在'宋'的建設中得到了強調,任何人都可以向我解釋這個問題是什麼?Typescript - 顯示下劃線參數 - 這裏有什麼問題

而不是隻是讓我的代碼糾正,我在這裏尋找正確的理解。

這裏是我的代碼:

class Song { 

artist:string, title:string - both underlined 
    constructor(artist:string, title:string) {} 

    play() { 
     console.log('Playing' + this.title + ' by' + this.artist); 
    } 

} 

var songs = [ 

    new Song('Bushbaby', 'Megaphone'), 
    new Song('Delays', 'One More Lie In'), 
    new Song('Goober Gun', 'Stereo'), 
    new Song('Sohnee', 'Shatter'), 
    new Song('Get Amped', 'Celebrity') 

]; 

class Jukebox { 

    constructor(private songs: Song[]) { }; 

    run() { 

     var song = this.getRandomSong(); 
     song.play(); 
    }; 

    private getRandomSong() { 

     var songCount = this.songs.length; 
     var songIndex = Math.floor(Math.random() * songCount); 

     return this.songs[songIndex]; 

    }; 
} 



var jukebox = new Jukebox(songs); 
jukebox.run(); 

Live

回答

0

只需使用一些分號,我認爲你是好。

artist:string; 
title:string; 

Updated Live

+0

您可以在現場演示更新? – user2024080

+0

@ user2024080完成後,將鏈接添加到我的答案中 – spozun