Creating instances of generic variables

JavaScript libraries often use the options pattern. All functionality options are represented by option classes, and have global default values represented by default option class instances. This way, the developer doesn't need to specify a whole option object that might contain hundreds of properties, but just the properties that differ from the default.

For instance, in the case of a graphic library, a very simplified option class might be something such as:

class GraphicStyle {    pencilWidth: number;    pencilType: string;    foregroundColor: string;    backgroundColor: string;    colors(): string {        return this.foregroundColor + " " + this.backgroundColor;    }    pencil(): string { return this.pencilWidth + " " + this.backgroundColor; ...

Get Hands-On TypeScript for C# and .NET Core Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.