Unfortunately, there is no direct method available to achieve this functionality. However, you could potentially create a utility function that acts as a workaround, essentially abstracting the existing process. The crux of the matter lies in the absence of a specific `new` method (akin to Java's `User::new`). Instead, the existence of the `User` function itself determines whether it generates a new `User` instance or triggers an error when called. In modern environments, invoking it with `new` or similar constructs like `Reflect.construct` will result in the creation of a `User` instance. Conversely, calling it directly would lead to an error (in ES2015+; although in ES5 compilation, it may not throw an error but also won't function correctly).
The alternative solution you have implemented using a wrapper arrow function is indeed a valid approach and likely what I would recommend as well.
If you find yourself needing this functionality across multiple instances, integrating a static method within the `User` class could prove beneficial:
class User {
// ...
static create(...args) {
return new User(...args);
}
}
// ...
const users = userObjects.map(User.create);
(It's worth noting that the `create` method may not operate as expected in subclasses of `User` [depending on your criteria for "proper functionality"], as it always generates a `User` instance regardless of being invoked as `UserSubclass.create(/*...*/)`). Typically, leveraging `this` instead of `User` (`new this(...args)`) might seem unconventional but can work effectively if the call accurately sets `this` [such as with `User.create(/*...*/)` or `UserSubclass.create(/*...*/)`]. Nonetheless, due to `map` inadequately handling `this` context, this approach fails unless you either bind `create` or remember to pass the second argument to `map` [`.map(User.create, User)`]). Therefore, reverting back to utilizing a wrapper arrow function appears to be the more pragmatic choice.)