_baseCreate.js 535 B

12345678910111213141516171819
  1. import isObject from './isObject.js';
  2. import { nativeCreate } from './_setup.js';
  3. // Create a naked function reference for surrogate-prototype-swapping.
  4. function ctor() {
  5. return function(){};
  6. }
  7. // An internal function for creating a new object that inherits from another.
  8. export default function baseCreate(prototype) {
  9. if (!isObject(prototype)) return {};
  10. if (nativeCreate) return nativeCreate(prototype);
  11. var Ctor = ctor();
  12. Ctor.prototype = prototype;
  13. var result = new Ctor;
  14. Ctor.prototype = null;
  15. return result;
  16. }