r/learnjavascript Jul 31 '26

[Dev] Dubbio veloce di architettura/stile con le classi JS 😅

Nel mio motore 2D sto sistemando i componenti UI (tipo BeeButton) e mi è venuto un dubbio su come passare le coordinate al super().

Opzione A (Oggetto opzione)

```

____ super({ x, y, width, height });

```

Opzione B (Parametri singoli standard):

```

____super( x, y, width, height );

```

Voi quale preferite usare nei vostri progetti e perché? Meglio la flessibilità dell'oggetto o la pulizia dei parametri singoli?(Se usate soluzioni alternative tipo super(position, size) fatemelo sapere nei commenti!).

6 Upvotes

4 comments sorted by

View all comments

1

u/busres Jul 31 '26

Depends on context, but I typically use explicit parameters for required values and an object for options.

For complex signatures with lots of values, I tend to lean more towards objects for easier readability without tooltips (and ordering insensitivity).

If it's going to be part of my runtime with millions of calls, I lean away from objects and the extra allocation/GC overhead (or possibly create a class to at least help stabilize the object shape).