inherit-if-required.js 693 B

1234567891011121314151617
  1. var isObject = require('../internals/is-object');
  2. var setPrototypeOf = require('../internals/object-set-prototype-of');
  3. // makes subclassing work correct for wrapped built-ins
  4. module.exports = function ($this, dummy, Wrapper) {
  5. var NewTarget, NewTargetPrototype;
  6. if (
  7. // it can work only with native `setPrototypeOf`
  8. setPrototypeOf &&
  9. // we haven't completely correct pre-ES6 way for getting `new.target`, so use this
  10. typeof (NewTarget = dummy.constructor) == 'function' &&
  11. NewTarget !== Wrapper &&
  12. isObject(NewTargetPrototype = NewTarget.prototype) &&
  13. NewTargetPrototype !== Wrapper.prototype
  14. ) setPrototypeOf($this, NewTargetPrototype);
  15. return $this;
  16. };