mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
Simplify baseCreate.
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
import isObject from './isObject.js';
|
||||
|
||||
/** Built-in value references. */
|
||||
const objectCreate = Object.create;
|
||||
|
||||
/**
|
||||
* The base implementation of `create` without support for assigning
|
||||
* properties to the created object.
|
||||
@@ -11,20 +8,8 @@ const objectCreate = Object.create;
|
||||
* @param {Object} proto The object to inherit from.
|
||||
* @returns {Object} Returns the new object.
|
||||
*/
|
||||
const baseCreate = (() => {
|
||||
function object() {}
|
||||
return proto => {
|
||||
if (!isObject(proto)) {
|
||||
return {};
|
||||
}
|
||||
if (objectCreate) {
|
||||
return objectCreate(proto);
|
||||
}
|
||||
object.prototype = proto;
|
||||
const result = new object;
|
||||
object.prototype = undefined;
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
function baseCreate(proto) {
|
||||
return isObject(proto) ? Object.create(proto) : {};
|
||||
}
|
||||
|
||||
export default baseCreate;
|
||||
|
||||
Reference in New Issue
Block a user