Working with JavaScript function context can be tricky, but one important thing to remember is that when you reassign a function, it will adopt the context of the object it's assigned to. This means that `this` will point to the new object being created.
There are various approaches to maintaining this context, with one common method involving binding the function to the object instance:
{
loginByJSON: user.loginByJSON.bind(user),
}
Another way is to use instance-bound methods like this:
loginByJSON = (req: any, res: any, next: any) => {
this.mytest(req, res, next);
}
By using instance-bound methods, the method will always be linked to that specific instance. The downside is that a new function is created for each instance, but if you're only creating one instance and doing this for organizational purposes, it shouldn't be a major issue.