Skip to content

Commit 915d876

Browse files
committed
chore: bind functions
1 parent ff68f92 commit 915d876

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/image.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ export class Image {
1313
readonly lorempicsum: typeof LoremPicsum;
1414

1515
constructor(private readonly faker: Faker) {
16+
// Bind `this` so namespaced is working correctly
17+
for (const name of Object.getOwnPropertyNames(Image.prototype)) {
18+
if (name === 'constructor' || typeof this[name] !== 'function') {
19+
continue;
20+
}
21+
this[name] = this[name].bind(this);
22+
}
23+
1624
this.lorempixel = new Lorempixel(this.faker);
1725
this.unsplash = new Unsplash(this.faker);
1826
this.lorempicsum = new LoremPicsum(this.faker);

0 commit comments

Comments
 (0)