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

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.

主站蜘蛛池模板: 浦江县| 略阳县| 康乐县| 五常市| 无为县| 玉林市| 栖霞市| 元朗区| 津市市| 阜城县| 蒙阴县| 博罗县| 平度市| 呼伦贝尔市| 抚州市| 郓城县| 铅山县| 吴川市| 商南县| 永修县| 五大连池市| 襄垣县| 万源市| 岳西县| 萨嘎县| 华安县| 赞皇县| 株洲县| 耿马| 沾化县| 林芝县| 昌图县| 克拉玛依市| 平武县| 民和| 奉贤区| 夏津县| 兴文县| 策勒县| 灵璧县| 大足县|