API Reference Source

lib/utils/classToInvokable.js

  1. 'use strict';
  2.  
  3. /**
  4. * Wraps a constructor to not need the `new` keyword using a proxy.
  5. * Only used for data types.
  6. *
  7. * @param {Function} Class The class instance to wrap as invocable.
  8. * @returns {Proxy} Wrapped class instance.
  9. * @private
  10. */
  11. function classToInvokable(Class) {
  12. return new Proxy(Class, {
  13. apply(Target, thisArg, args) {
  14. return new Target(...args);
  15. },
  16. construct(Target, args) {
  17. return new Target(...args);
  18. },
  19. get(target, p) {
  20. return target[p];
  21. }
  22. });
  23. }
  24. exports.classToInvokable = classToInvokable;