Is it possible to enhance specific class methods in TypeScript by making them prototypes, even when the target is ES6?
Additionally, can a specific class be configured to only produce prototypes?
Consider the following TypeScript class:
class Test {
constructor() {
}
methodName() {
}
}
When targeting ES6, the resulting JavaScript code remains the same. However, I aim for:
class Test {
constructor() {
}
}
Test.prototype.methodName = function () {
}
Whether it's for a single method or all methods within the class, the goal is to generate prototypes despite utilizing ES6 as the primary target.
The inquiry arises from the necessity of creating numerous class instances within a module, with the understanding that prototypes may offer better performance in this scenario, as discussed in these posts:
- Javascript prototype operator performance
- Defining methods via prototype vs using this in the constructor
P.S. This inquiry mainly pertains to server-side applications, particularly Node.js versions 4-8.