上QQ阅读APP看书,第一时间看更新
Using the class export feature
Any declaration can be exported, as we mentioned previously; to do so, we just need to add the export keyword. In the following example, we will export the band class.
In your text editor, create a file called export.ts, and add the following code:
export class MyBand {
// Properties without prefix are public
// Available is; Private, Protected
albums: Array<string>;
members: number;
constructor(albums_list: Array<string>, total_members: number) {
this.albums = albums_list;
this.members = total_members;
}
// Methods
listAlbums(): void {
console.log("My favorite albums: ");
for(var i = 0; i < this.albums.length; i++) {
console.log(this.albums[i]);
}
}
}
We will now have our Myband class available to be imported into another file.