UNPKG

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