From a4e3ea3117209c624ae2f3bb9be4d04c5234cb5d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 8 Dec 2022 18:06:31 +0100 Subject: [PATCH] Fix the access to the prototype during the object initialization MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit `_readField()` is implicitly called in the constructor of the parent class. This is effectively an attempt to access `this` while `super()` is still running which is a silent violation of the specs. The `_fields` property in line 15 is actually implicitly declared in the constructor *after* `super()` has completed. JavaScript’s technical debts strike again. --- ts/WoltLabSuite/Core/Form/Builder/Field/RadioButton.ts | 8 +++++++- .../WoltLabSuite/Core/Form/Builder/Field/RadioButton.js | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ts/WoltLabSuite/Core/Form/Builder/Field/RadioButton.ts b/ts/WoltLabSuite/Core/Form/Builder/Field/RadioButton.ts index 2836b44ee7..5a43e5e1d9 100644 --- a/ts/WoltLabSuite/Core/Form/Builder/Field/RadioButton.ts +++ b/ts/WoltLabSuite/Core/Form/Builder/Field/RadioButton.ts @@ -14,6 +14,12 @@ import { FormBuilderData } from "../Data"; class RadioButton extends Field { protected _fields: HTMLInputElement[]; + constructor(fieldId: string) { + super(fieldId); + + this._fields = Array.from(document.querySelectorAll("input[name=" + this._fieldId + "]")); + } + protected _getData(): FormBuilderData { const data = {}; @@ -30,7 +36,7 @@ class RadioButton extends Field { } protected _readField(): void { - this._fields = Array.from(document.querySelectorAll("input[name=" + this._fieldId + "]")); + /* Does nothing. */ } } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/RadioButton.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/RadioButton.js index 0562477441..294cfc1541 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/RadioButton.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/RadioButton.js @@ -12,6 +12,10 @@ define(["require", "exports", "tslib", "./Field"], function (require, exports, t Field_1 = tslib_1.__importDefault(Field_1); class RadioButton extends Field_1.default { _fields; + constructor(fieldId) { + super(fieldId); + this._fields = Array.from(document.querySelectorAll("input[name=" + this._fieldId + "]")); + } _getData() { const data = {}; this._fields.some((input) => { @@ -24,7 +28,7 @@ define(["require", "exports", "tslib", "./Field"], function (require, exports, t return data; } _readField() { - this._fields = Array.from(document.querySelectorAll("input[name=" + this._fieldId + "]")); + /* Does nothing. */ } } return RadioButton; -- 2.20.1