官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 老河口市| 鄢陵县| 沁阳市| 宜宾县| 客服| 商都县| 南宁市| 沐川县| 仙桃市| 怀集县| 将乐县| 吉木萨尔县| 宣城市| 大洼县| 神农架林区| 阿坝县| 合阳县| 阜宁县| 富平县| 灵川县| 云和县| 娄烦县| 兰西县| 商水县| 南乐县| 政和县| 横峰县| 大城县| 平昌县| 乌拉特中旗| 郸城县| 荆州市| 泰顺县| 娱乐| 黑水县| 错那县| 岫岩| 梁河县| 化德县| 突泉县| 城步|