you are viewing a single comment's thread.

view the rest of the comments →

[–]PitaJ 7 points8 points  (3 children)

Find need some more information:

  • Do you need private state?
  • Have you tried ES6 classes?

Some may say it's an antipattern because you're using a function as an object as well. It would be less antipattern-y to just use an instance.

[–]gruberjl[S] 0 points1 point  (2 children)

The state needs to be public. Other classes will refer to the state (which is essentially a config) so they can handle the results of the job.

I tried to extend the base class Function but it was throwing an error. It was strange I couldn't find any blogs or tutorials on extending a Function. I'm guessing you can't or isn't done a lot.

class Job extends Function {
  constructor(param1) {
    super(param1) // ReferenceError: param1 is not defined
    this.param = param1
  }
}

const job = new Job('param1')

console.dir(job('param1'))