UNPKG

938 BJavaScriptView Raw
1var setPrototypeOf = require("./setPrototypeOf");
2
3function 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
8 try {
9 Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
10 return true;
11 } catch (e) {
12 return false;
13 }
14}
15
16function _construct(Parent, args, Class) {
17 if (isNativeReflectConstruct()) {
18 module.exports = _construct = Reflect.construct;
19 } else {
20 module.exports = _construct = function _construct(Parent, args, Class) {
21 var a = [null];
22 a.push.apply(a, args);
23 var Constructor = Function.bind.apply(Parent, a);
24 var instance = new Constructor();
25 if (Class) setPrototypeOf(instance, Class.prototype);
26 return instance;
27 };
28 }
29
30 return _construct.apply(null, arguments);
31}
32
33module.exports = _construct;
\No newline at end of file