You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
938 B

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