yorkie / me

CV at Github and Notes based on Issues

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pass through arguments to Instantiate the given class

yorkie opened this issue · comments

Here is the demo function:

// utils for pass a class constructor and arguments, and return the
// instance of the given class.
function passthroughModule(initializer, args) {
  return new (Function.prototype.bind.apply(initializer, [null].concat(args)));
}

Then we would use this function:

class Foo { ... }
passthroughModule(Foo, args);