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