Remove baseCreate.

This commit is contained in:
John-David Dalton
2017-02-05 23:43:43 -08:00
parent 7479d282bc
commit b0980a90fc
7 changed files with 6 additions and 143 deletions

View File

@@ -3,7 +3,6 @@ import arrayEach from './arrayEach.js'
import assignValue from './assignValue.js'
import baseAssign from './baseAssign.js'
import baseAssignIn from './baseAssignIn.js'
import baseCreate from './baseCreate.js'
import cloneBuffer from './cloneBuffer.js'
import copyArray from './copyArray.js'
import cloneArrayBuffer from './cloneArrayBuffer.js'
@@ -88,7 +87,7 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
*/
function initCloneObject(object) {
return (typeof object.constructor == 'function' && !isPrototype(object))
? baseCreate(Object.getPrototypeOf(object))
? Object.create(Object.getPrototypeOf(object))
: {}
}
@@ -150,7 +149,7 @@ function initCloneByTag(object, tag, cloneFunc, isDeep) {
*/
function initCloneArray(array) {
const length = array.length
const result = array.constructor(length)
const result = new array.constructor(length)
// Add properties assigned by `RegExp#exec`.
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {

View File

@@ -1,15 +0,0 @@
import isObject from '../isObject.js'
/**
* The base implementation of `create` without support for assigning
* properties to the created object.
*
* @private
* @param {Object} proto The object to inherit from.
* @returns {Object} Returns the new object.
*/
function baseCreate(proto) {
return isObject(proto) ? Object.create(proto) : {}
}
export default baseCreate

View File

@@ -1,4 +1,3 @@
import baseCreate from './baseCreate.js'
import isObject from '../isObject.js'
/**
@@ -24,7 +23,8 @@ function createCtor(Ctor) {
case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5])
case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6])
}
const thisBinding = baseCreate(Ctor.prototype)
const proto = Ctor.prototype
const thisBinding = proto == null ? {} : Object.create(Object(proto))
const result = Ctor.apply(thisBinding, args)
// Mimic the constructor's `return` behavior.

View File

@@ -1,23 +0,0 @@
/** Used to check objects for own properties. */
const hasOwnProperty = Object.prototype.hasOwnProperty
/**
* Initializes an array clone.
*
* @private
* @param {Array} array The array to clone.
* @returns {Array} Returns the initialized clone.
*/
function initCloneArray(array) {
const length = array.length
const result = new array.constructor(length)
// Add properties assigned by `RegExp#exec`.
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
result.index = array.index
result.input = array.input
}
return result
}
export default initCloneArray

View File

@@ -1,80 +0,0 @@
import cloneArrayBuffer from './.internal/cloneArrayBuffer.js'
import cloneDataView from './.internal/cloneDataView.js'
import cloneMap from './.internal/cloneMap.js'
import cloneRegExp from './.internal/cloneRegExp.js'
import cloneSet from './.internal/cloneSet.js'
import cloneSymbol from './.internal/cloneSymbol.js'
import cloneTypedArray from './.internal/cloneTypedArray.js'
/** `Object#toString` result references. */
const boolTag = '[object Boolean]'
const dateTag = '[object Date]'
const mapTag = '[object Map]'
const numberTag = '[object Number]'
const regexpTag = '[object RegExp]'
const setTag = '[object Set]'
const stringTag = '[object String]'
const symbolTag = '[object Symbol]'
const arrayBufferTag = '[object ArrayBuffer]'
const dataViewTag = '[object DataView]'
const float32Tag = '[object Float32Array]'
const float64Tag = '[object Float64Array]'
const int8Tag = '[object Int8Array]'
const int16Tag = '[object Int16Array]'
const int32Tag = '[object Int32Array]'
const uint8Tag = '[object Uint8Array]'
const uint8ClampedTag = '[object Uint8ClampedArray]'
const uint16Tag = '[object Uint16Array]'
const uint32Tag = '[object Uint32Array]'
/**
* Initializes an object clone based on its `toStringTag`.
*
* **Note:** This function only supports cloning values with tags of
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
*
* @private
* @param {Object} object The object to clone.
* @param {string} tag The `toStringTag` of the object to clone.
* @param {Function} cloneFunc The function to clone values.
* @param {boolean} [isDeep] Specify a deep clone.
* @returns {Object} Returns the initialized clone.
*/
function initCloneByTag(object, tag, cloneFunc, isDeep) {
const Ctor = object.constructor
switch (tag) {
case arrayBufferTag:
return cloneArrayBuffer(object)
case boolTag:
case dateTag:
return new Ctor(+object)
case dataViewTag:
return cloneDataView(object, isDeep)
case float32Tag: case float64Tag:
case int8Tag: case int16Tag: case int32Tag:
case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
return cloneTypedArray(object, isDeep)
case mapTag:
return cloneMap(object, isDeep, cloneFunc)
case numberTag:
case stringTag:
return new Ctor(object)
case regexpTag:
return cloneRegExp(object)
case setTag:
return cloneSet(object, isDeep, cloneFunc)
case symbolTag:
return cloneSymbol(object)
}
}
export default initCloneByTag

View File

@@ -1,17 +0,0 @@
import baseCreate from './.internal/baseCreate.js'
import isPrototype from './.internal/isPrototype.js'
/**
* Initializes an object clone.
*
* @private
* @param {Object} object The object to clone.
* @returns {Object} Returns the initialized clone.
*/
function initCloneObject(object) {
return (typeof object.constructor == 'function' && !isPrototype(object))
? baseCreate(Object.getPrototypeOf(object))
: {}
}
export default initCloneObject

View File

@@ -1,5 +1,3 @@
import baseCreate from './.internal/baseCreate.js'
/**
* Creates an object that inherits from the `prototype` object. If a
* `properties` object is given, its own enumerable string keyed properties
@@ -33,7 +31,8 @@ import baseCreate from './.internal/baseCreate.js'
* // => true
*/
function create(prototype, properties) {
const result = baseCreate(prototype)
prototype = prototype === null ? null : Object(prototype)
const result = Object.create(prototype)
return properties == null ? result : Object.assign(result, properties)
}