Skip to content

Commit

Permalink
chore: bind methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Jan 11, 2022
1 parent d1f2b34 commit 3aa8be8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/fake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import type { Faker } from '.';
* Generator method for combining faker methods based on string input
*/
export class Fake {
constructor(private readonly faker: Faker) {}
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Fake.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
this[name] = this[name].bind(this);
}
}

/**
* Generator method for combining faker methods based on string input
Expand Down

0 comments on commit 3aa8be8

Please sign in to comment.