I have a number of artworks I want to put into an array of arrays. each artwork has properties I'm trying to describe with a class. I want to create the types with the class and push data onto the array. I'm not sure what the constructor is doing either? I think it should provide a way of creating a new instance of the class?
My ts code is as follows:
class Artwork {
private _artTitle: string;
private _slideUrl: string;
private _artPrice: string;
private _artMedium: string;
private _artDimensions: string;
private _artDesc: string;
constructor(
artTitle: string,
slideUrl: string,
artPrice: string,
artMedium: string,
artDimensions: string,
artDesc: string
){
this._artTitle = artTitle;
this._slideUrl = slideUrl;
this._artPrice = artPrice;
this._artMedium = artMedium;
this._artDimensions = artDimensions;
this._artDesc = artDesc;
}
}
let Artwks: string [];
Artwks.push(new Artwork());
Artwks[0].slideUrl = './assets/SBI_Slide_1.jpg';
Artwks[0].artTitle = "'Surprising Breakfast Ideas'";
Artwks[0].artPrice = "£400";
Artwks[0].artMedium = "Acrylic on canvas";
Artwks[0].artDimensions = '7" x 12"';
Artwks[0].artDesc = '...Inspired by trailing clauses and footling concerns, this latest injunction into the darkened forest of prevarication yields a miasma of plethoras, tantalising us with a fleeting array of nuances...';
console.log(Artwks);
private/protected/publicand then access it without having to separately declare class variables and then assign values from the constructor to them. E.g.constructor(private _artTitle: string)