inherit-if-required.js 736 B

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