How to fix the code below to be able to call the class method using call .
Class definition:
class User { constructor(..) {...} async method(start, end) {} }
Trying to pass a class method as an argument to a function:
const User = require('./user'); async function getData(req, res) { // User.method is undefined, since User refers to User constructor await get(req, res, User.method); } async function get(req, res, f) { let start = ...; let end = ...; let params = ...; let user = new User(params); // f is undefined here let stream = await f.call(user, start, end); }
source share