_construct.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = _construct;
  6. var _setPrototypeOfMjs = _interopRequireDefault(require("./_set_prototype_of.js"));
  7. function _construct(Parent, args, Class) {
  8. return construct.apply(null, arguments);
  9. }
  10. function _interopRequireDefault(obj) {
  11. return obj && obj.__esModule ? obj : {
  12. default: obj
  13. };
  14. }
  15. function isNativeReflectConstruct() {
  16. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  17. if (Reflect.construct.sham) return false;
  18. if (typeof Proxy === "function") return true;
  19. try {
  20. Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
  21. return true;
  22. } catch (e) {
  23. return false;
  24. }
  25. }
  26. function construct(Parent1, args1, Class1) {
  27. if (isNativeReflectConstruct()) {
  28. construct = Reflect.construct;
  29. } else {
  30. construct = function construct(Parent, args, Class) {
  31. var a = [
  32. null
  33. ];
  34. a.push.apply(a, args);
  35. var Constructor = Function.bind.apply(Parent, a);
  36. var instance = new Constructor();
  37. if (Class) (0, _setPrototypeOfMjs).default(instance, Class.prototype);
  38. return instance;
  39. };
  40. }
  41. return construct.apply(null, arguments);
  42. }