aboutsummaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
authorShinigami <[email protected]>2023-09-18 05:52:42 +0200
committerGitHub <[email protected]>2023-09-18 05:52:42 +0200
commitd6a4f8c2ddf9e957e875bc3fab77e496104d1320 (patch)
tree8c87a5d2baf4dfad8d96da7a4823adaf8bd005ee /src/internal
parentf40e217c6275ab555ecbe3ca0046526e44b31263 (diff)
downloadfaker-d6a4f8c2ddf9e957e875bc3fab77e496104d1320.tar.xz
faker-d6a4f8c2ddf9e957e875bc3fab77e496104d1320.zip
feat: split SimpleFaker class from Faker (#2369)
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/bind-this-to-member-functions.ts15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/internal/bind-this-to-member-functions.ts b/src/internal/bind-this-to-member-functions.ts
index f2a9d3d5..26b7cfe4 100644
--- a/src/internal/bind-this-to-member-functions.ts
+++ b/src/internal/bind-this-to-member-functions.ts
@@ -15,11 +15,14 @@
export function bindThisToMemberFunctions<TClass extends { new (): any }>(
instance: InstanceType<TClass>
): void {
- for (const name of Object.getOwnPropertyNames(
- Object.getPrototypeOf(instance)
- )) {
- if (typeof instance[name] === 'function' && name !== 'constructor') {
- instance[name] = instance[name].bind(instance);
+ let p = Object.getPrototypeOf(instance);
+ do {
+ for (const name of Object.getOwnPropertyNames(p)) {
+ if (typeof instance[name] === 'function' && name !== 'constructor') {
+ instance[name] = instance[name].bind(instance);
+ }
}
- }
+
+ p = Object.getPrototypeOf(p);
+ } while (p !== Object.prototype);
}