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

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.

主站蜘蛛池模板: 文昌市| 鸡泽县| 郑州市| 西宁市| 石河子市| 金平| 古浪县| 册亨县| 象州县| 射阳县| 阿巴嘎旗| 葵青区| 元阳县| 湄潭县| 获嘉县| 曲阳县| 和田市| 深泽县| 威远县| 蒙城县| 南和县| 盐津县| 九江市| 财经| 砚山县| 伊金霍洛旗| 上饶市| 辽阳市| 彝良县| 竹北市| 河北省| 尤溪县| 镇沅| 遂昌县| 钦州市| 南郑县| 彭泽县| 阳信县| 吉首市| 华宁县| 家居|