This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const prototype = { | |
greeting: "Hello!", | |
greet: function() { | |
console.log(this.greeting); | |
}, | |
clone: function() { | |
return Object.create(this); | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Prototype from "./class" | |
interface Modified extends Prototype { | |
farewell: () => void; | |
} | |
const prototype: Prototype = new Prototype(); | |
const cloned: Modified = <Modified>prototype.clone(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Prototype { | |
greeting: string = "Hello!"; | |
greet(): void { | |
console.log(this.greeting); | |
} | |
clone(): Prototype { | |
return new Prototype(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Prototype { | |
greeting = "Hello!"; | |
greet() { | |
console.log(this.greeting); | |
} | |
clone() { | |
return new this.constructor(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function configureEvent(config: ConfigurationArgs): void { | |
let createEvent; | |
switch (config.os) { | |
case 'ios': | |
createEvent = createAppleEvent; | |
break; | |
case 'chromeos': | |
createEvent = createGoogleEvent; | |
break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function application(createEvent: CreateEvent): void { | |
createEvent({name: 'Abstract Factory Pattern', date: new Date(), participants: []}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createOutlookEvent({name, date, participants}: CreateEventArgs): void { | |
MicrosoftAPI.createEvent({title: name, date, users: participants}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createAppleEvent({name, date, participants}: CreateEventArgs): void { | |
AppleAPI.createEvent({name, date, participants}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createGoogleEvent({name, date, participants}: CreateEventArgs): void { | |
GoogleAPI.createEvent({title: name, date, invitees: participants}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface CreateEventArgs { | |
name: string; | |
date: Date; | |
participants: string[]; | |
} | |
export interface ConfigurationArgs { | |
os: 'ios' | 'chromeos' | 'windows'; | |
} |