Created
February 1, 2023 14:38
-
-
Save xaliphostes/b6c3fe9174ba17b839b87af7898df30e to your computer and use it in GitHub Desktop.
Create an object instance
This file contains 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 create = (Type: any, params: any) => new Type(params) | |
// -------------------------------------------------------- | |
// Example | |
class A { | |
private a = 0 | |
private b = 0 | |
constructor({a: number, b: number}) { | |
this.a = a | |
this.b = b | |
} | |
display() { | |
console.log(this.a, this.b) | |
} | |
} | |
const a = create(A, {a: 0,b: 1}) | |
a.display() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment