construct.js 614 B

1234567891011121314151617
  1. import setPrototypeOf from "./setPrototypeOf.js";
  2. import isNativeReflectConstruct from "./isNativeReflectConstruct.js";
  3. export default function _construct(Parent, args, Class) {
  4. if (isNativeReflectConstruct()) {
  5. _construct = Reflect.construct.bind();
  6. } else {
  7. _construct = function _construct(Parent, args, Class) {
  8. var a = [null];
  9. a.push.apply(a, args);
  10. var Constructor = Function.bind.apply(Parent, a);
  11. var instance = new Constructor();
  12. if (Class) setPrototypeOf(instance, Class.prototype);
  13. return instance;
  14. };
  15. }
  16. return _construct.apply(null, arguments);
  17. }