construct.js 1009 B

1234567891011121314151617181920212223242526272829303132333435
  1. var _Reflect$construct = require("../core-js/reflect/construct");
  2. var setPrototypeOf = require("./setPrototypeOf");
  3. function isNativeReflectConstruct() {
  4. if (typeof Reflect === "undefined" || !_Reflect$construct) return false;
  5. if (_Reflect$construct.sham) return false;
  6. if (typeof Proxy === "function") return true;
  7. try {
  8. Date.prototype.toString.call(_Reflect$construct(Date, [], function () {}));
  9. return true;
  10. } catch (e) {
  11. return false;
  12. }
  13. }
  14. function _construct(Parent, args, Class) {
  15. if (isNativeReflectConstruct()) {
  16. module.exports = _construct = _Reflect$construct;
  17. } else {
  18. module.exports = _construct = function _construct(Parent, args, Class) {
  19. var a = [null];
  20. a.push.apply(a, args);
  21. var Constructor = Function.bind.apply(Parent, a);
  22. var instance = new Constructor();
  23. if (Class) setPrototypeOf(instance, Class.prototype);
  24. return instance;
  25. };
  26. }
  27. return _construct.apply(null, arguments);
  28. }
  29. module.exports = _construct;