From b16ec1b25e5e6ecc60ca1527aca3d941e2545af2 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Tue, 11 Jan 2022 09:22:33 +0100 Subject: [PATCH] chore: dynamically bind functions --- src/datatype.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/datatype.ts b/src/datatype.ts index 05960228b83..1da3caceb52 100644 --- a/src/datatype.ts +++ b/src/datatype.ts @@ -10,16 +10,12 @@ export class Datatype { } // Bind `this` so namespaced is working correctly - this.number = this.number.bind(this); - this.float = this.float.bind(this); - this.datetime = this.datetime.bind(this); - this.string = this.string.bind(this); - this.uuid = this.uuid.bind(this); - this.boolean = this.boolean.bind(this); - this.hexaDecimal = this.hexaDecimal.bind(this); - this.json = this.json.bind(this); - this.array = this.array.bind(this); - this.bigInt = this.bigInt.bind(this); + for (const name of Object.getOwnPropertyNames(Datatype.prototype)) { + if (name === 'constructor' || typeof this[name] !== 'function') { + continue; + } + this[name] = this[name].bind(this); + } } /**