class Movie { name: string; play_count: number; create_at: string; constructor(name: string, play_count: number = 12, create_at: string) { // this 指向生成點 Object 本身 this.name = name; this.play_count = play_count; this.create_at = create_at; } // methods 可以對 data 進行操作 display_play_count(padding: string = '***') { return this.play_count + '次' + padding } increase_play_count() { this.play_count += 1; } } let a = new Movie('阿麗塔:戰斗天使', undefined, '17點28分'); a.increase_play_count(); // 13*** 雖然第二個參數並沒有傳遞 可以使用 undefined 來占位 會使用默認值 12 再 += 1 console.log(a, a.display_play_count()); // Movie { name: '阿麗塔:戰斗天使', play_count: 13, create_at: '17點28分' } '13次***'