Name Preservation Matters
When you compile a standard TQTXWidget class, a field like FHeader might be compiled into JavaScript as _aH to save space. This is fine because all your Pascal code is compiled together and "knows" about this change.
But anonymous classes are specifically for interfacing with external JavaScript libraries. If a library expects an object with a field named first, you must pass it an object with that exact name.
- An anonymous record's fields might be obfuscated ({_a: 12}).
- An anonymous class's fields are guaranteed to be preserved ({first: 12}).
This makes anonymous classes the perfect tool for creating complex parameter objects that external JavaScript APIs expect.
For these reasons, it is recommended to use anonymous classes instead of anonymous records whenever possible. They provide the same benefit of creating ad-hoc data structures but add the power of methods and the safety of name preservation, making them the superior choice for interfacing with the JavaScript world.