Skip to content

Commit

Permalink
chore: bind functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Jan 12, 2022
1 parent 605e66f commit 3ab384e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ export class Image {
readonly lorempicsum: typeof LoremPicsum;

constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Image.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
this[name] = this[name].bind(this);
}

this.lorempixel = new Lorempixel(this.faker);
this.unsplash = new Unsplash(this.faker);
this.lorempicsum = new LoremPicsum(this.faker);
Expand Down

0 comments on commit 3ab384e

Please sign in to comment.