若是你指望拥有若干个参数再创造一些实例对象 那如何写呢学习
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次***'
但愿看了以上代码 能够对你对学习 TS 有所帮助。this