From 04dad3c1c61f589949872ba18352703373eb771f Mon Sep 17 00:00:00 2001 From: PoseidonEnergy Date: Sun, 8 Mar 2026 17:35:48 -0500 Subject: [PATCH] Moved prototype field assignments out of constructors. --- src/math/Matrix2.js | 22 +++++++++++++--------- src/math/Matrix3.js | 22 +++++++++++++--------- src/math/Matrix4.js | 22 +++++++++++++--------- src/math/Vector2.js | 18 +++++++++++------- src/math/Vector3.js | 20 ++++++++++++-------- src/math/Vector4.js | 22 +++++++++++++--------- 6 files changed, 75 insertions(+), 51 deletions(-) diff --git a/src/math/Matrix2.js b/src/math/Matrix2.js index 3e096aefc66892..b7b82c1dd0d3e0 100644 --- a/src/math/Matrix2.js +++ b/src/math/Matrix2.js @@ -26,6 +26,19 @@ */ export class Matrix2 { + static { + + /** + * This flag can be used for type testing. + * + * @type {boolean} + * @readonly + * @default true + */ + Matrix2.prototype.isMatrix2 = true; + + } + /** * Constructs a new 2x2 matrix. The arguments are supposed to be * in row-major order. If no arguments are provided, the constructor @@ -38,15 +51,6 @@ export class Matrix2 { */ constructor( n11, n12, n21, n22 ) { - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - Matrix2.prototype.isMatrix2 = true; - /** * A column-major list of matrix values. * diff --git a/src/math/Matrix3.js b/src/math/Matrix3.js index 250dc5aa5abc36..8fd40cb24ab09c 100644 --- a/src/math/Matrix3.js +++ b/src/math/Matrix3.js @@ -28,6 +28,19 @@ */ class Matrix3 { + static { + + /** + * This flag can be used for type testing. + * + * @type {boolean} + * @readonly + * @default true + */ + Matrix3.prototype.isMatrix3 = true; + + } + /** * Constructs a new 3x3 matrix. The arguments are supposed to be * in row-major order. If no arguments are provided, the constructor @@ -45,15 +58,6 @@ class Matrix3 { */ constructor( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) { - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - Matrix3.prototype.isMatrix3 = true; - /** * A column-major list of matrix values. * diff --git a/src/math/Matrix4.js b/src/math/Matrix4.js index 78bb134b363b87..efacbf44ec420d 100644 --- a/src/math/Matrix4.js +++ b/src/math/Matrix4.js @@ -41,6 +41,19 @@ import { Vector3 } from './Vector3.js'; */ class Matrix4 { + static { + + /** + * This flag can be used for type testing. + * + * @type {boolean} + * @readonly + * @default true + */ + Matrix4.prototype.isMatrix4 = true; + + } + /** * Constructs a new 4x4 matrix. The arguments are supposed to be * in row-major order. If no arguments are provided, the constructor @@ -65,15 +78,6 @@ class Matrix4 { */ constructor( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) { - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - Matrix4.prototype.isMatrix4 = true; - /** * A column-major list of matrix values. * diff --git a/src/math/Vector2.js b/src/math/Vector2.js index 60c53582d228b6..7113eb6aace566 100644 --- a/src/math/Vector2.js +++ b/src/math/Vector2.js @@ -27,13 +27,7 @@ import { clamp } from './MathUtils.js'; */ class Vector2 { - /** - * Constructs a new 2D vector. - * - * @param {number} [x=0] - The x value of this vector. - * @param {number} [y=0] - The y value of this vector. - */ - constructor( x = 0, y = 0 ) { + static { /** * This flag can be used for type testing. @@ -44,6 +38,16 @@ class Vector2 { */ Vector2.prototype.isVector2 = true; + } + + /** + * Constructs a new 2D vector. + * + * @param {number} [x=0] - The x value of this vector. + * @param {number} [y=0] - The y value of this vector. + */ + constructor( x = 0, y = 0 ) { + /** * The x value of this vector. * diff --git a/src/math/Vector3.js b/src/math/Vector3.js index fee3a6db5ef445..8c76998107c815 100644 --- a/src/math/Vector3.js +++ b/src/math/Vector3.js @@ -28,14 +28,7 @@ import { Quaternion } from './Quaternion.js'; */ class Vector3 { - /** - * Constructs a new 3D vector. - * - * @param {number} [x=0] - The x value of this vector. - * @param {number} [y=0] - The y value of this vector. - * @param {number} [z=0] - The z value of this vector. - */ - constructor( x = 0, y = 0, z = 0 ) { + static { /** * This flag can be used for type testing. @@ -46,6 +39,17 @@ class Vector3 { */ Vector3.prototype.isVector3 = true; + } + + /** + * Constructs a new 3D vector. + * + * @param {number} [x=0] - The x value of this vector. + * @param {number} [y=0] - The y value of this vector. + * @param {number} [z=0] - The z value of this vector. + */ + constructor( x = 0, y = 0, z = 0 ) { + /** * The x value of this vector. * diff --git a/src/math/Vector4.js b/src/math/Vector4.js index 52c7d29407bf5f..445e40eea9c9bf 100644 --- a/src/math/Vector4.js +++ b/src/math/Vector4.js @@ -26,15 +26,7 @@ import { clamp } from './MathUtils.js'; */ class Vector4 { - /** - * Constructs a new 4D vector. - * - * @param {number} [x=0] - The x value of this vector. - * @param {number} [y=0] - The y value of this vector. - * @param {number} [z=0] - The z value of this vector. - * @param {number} [w=1] - The w value of this vector. - */ - constructor( x = 0, y = 0, z = 0, w = 1 ) { + static { /** * This flag can be used for type testing. @@ -45,6 +37,18 @@ class Vector4 { */ Vector4.prototype.isVector4 = true; + } + + /** + * Constructs a new 4D vector. + * + * @param {number} [x=0] - The x value of this vector. + * @param {number} [y=0] - The y value of this vector. + * @param {number} [z=0] - The z value of this vector. + * @param {number} [w=1] - The w value of this vector. + */ + constructor( x = 0, y = 0, z = 0, w = 1 ) { + /** * The x value of this vector. *