simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

construct.js (608B)


      1 import setPrototypeOf from "./setPrototypeOf.js";
      2 import isNativeReflectConstruct from "./isNativeReflectConstruct.js";
      3 export default function _construct(Parent, args, Class) {
      4   if (isNativeReflectConstruct()) {
      5     _construct = Reflect.construct;
      6   } else {
      7     _construct = function _construct(Parent, args, Class) {
      8       var a = [null];
      9       a.push.apply(a, args);
     10       var Constructor = Function.bind.apply(Parent, a);
     11       var instance = new Constructor();
     12       if (Class) setPrototypeOf(instance, Class.prototype);
     13       return instance;
     14     };
     15   }
     16 
     17   return _construct.apply(null, arguments);
     18 }