Skip to content

Instantly share code, notes, and snippets.

View d4ins's full-sized avatar
🤌
Coding...

Andrii Drozdov d4ins

🤌
Coding...
  • OX
  • Dublin, Ireland
View GitHub Profile
@d4ins
d4ins / object.js
Created February 11, 2023 09:28
2 Ways to Implement Prototype Pattern in JavaScript | Class implementation | object.js
const prototype = {
greeting: "Hello!",
greet: function() {
console.log(this.greeting);
},
clone: function() {
return Object.create(this);
},
@d4ins
d4ins / class-import.ts
Last active February 11, 2023 09:16
2 Ways to Implement Prototype Pattern in JavaScript | Class implementation | class-import.ts
import Prototype from "./class"
interface Modified extends Prototype {
farewell: () => void;
}
const prototype: Prototype = new Prototype();
const cloned: Modified = <Modified>prototype.clone();
@d4ins
d4ins / class.ts
Created February 11, 2023 08:56
2 Ways to Implement Prototype Pattern in JavaScript | Class implementation | class.ts
class Prototype {
greeting: string = "Hello!";
greet(): void {
console.log(this.greeting);
}
clone(): Prototype {
return new Prototype();
}
@d4ins
d4ins / class.js
Created February 11, 2023 08:25
2 Ways to Implement Prototype Pattern in JavaScript | Class implementation | class.js
class Prototype {
greeting = "Hello!";
greet() {
console.log(this.greeting);
}
clone() {
return new this.constructor();
}
@d4ins
d4ins / configureEvent.ts
Created February 3, 2023 05:57
2 ways to implement Abstract Factory Pattern in JavaScript | Functional | configureEvent.ts
function configureEvent(config: ConfigurationArgs): void {
let createEvent;
switch (config.os) {
case 'ios':
createEvent = createAppleEvent;
break;
case 'chromeos':
createEvent = createGoogleEvent;
break;
@d4ins
d4ins / application.ts
Created February 3, 2023 05:56
2 ways to implement Abstract Factory Pattern in JavaScript | Functional | application.ts
function application(createEvent: CreateEvent): void {
createEvent({name: 'Abstract Factory Pattern', date: new Date(), participants: []});
}
@d4ins
d4ins / createOutlookEvent.ts
Created February 3, 2023 05:55
2 ways to implement Abstract Factory Pattern in JavaScript | Functional | createOutlookEvent.ts
function createOutlookEvent({name, date, participants}: CreateEventArgs): void {
MicrosoftAPI.createEvent({title: name, date, users: participants});
}
@d4ins
d4ins / createAppleEvent.ts
Created February 3, 2023 05:55
2 ways to implement Abstract Factory Pattern in JavaScript | Functional | createAppleEvent.ts
function createAppleEvent({name, date, participants}: CreateEventArgs): void {
AppleAPI.createEvent({name, date, participants});
}
@d4ins
d4ins / createGoogleEvent.ts
Created February 3, 2023 05:54
2 ways to implement Abstract Factory Pattern in JavaScript | Functional | createGoogleEvent.ts
function createGoogleEvent({name, date, participants}: CreateEventArgs): void {
GoogleAPI.createEvent({title: name, date, invitees: participants});
}
@d4ins
d4ins / types.ts
Created February 3, 2023 05:53
2 ways to implement Abstract Factory Pattern in JavaScript | Functional | types.ts
export interface CreateEventArgs {
name: string;
date: Date;
participants: string[];
}
export interface ConfigurationArgs {
os: 'ios' | 'chromeos' | 'windows';
}