mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Bump to v3.0.0.
This commit is contained in:
46
object/create.js
Normal file
46
object/create.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import baseCopy from '../internal/baseCopy';
|
||||
import baseCreate from '../internal/baseCreate';
|
||||
import isIterateeCall from '../internal/isIterateeCall';
|
||||
import keys from './keys';
|
||||
|
||||
/**
|
||||
* Creates an object that inherits from the given `prototype` object. If a
|
||||
* `properties` object is provided its own enumerable properties are assigned
|
||||
* to the created object.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Object
|
||||
* @param {Object} prototype The object to inherit from.
|
||||
* @param {Object} [properties] The properties to assign to the object.
|
||||
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
||||
* @returns {Object} Returns the new object.
|
||||
* @example
|
||||
*
|
||||
* function Shape() {
|
||||
* this.x = 0;
|
||||
* this.y = 0;
|
||||
* }
|
||||
*
|
||||
* function Circle() {
|
||||
* Shape.call(this);
|
||||
* }
|
||||
*
|
||||
* Circle.prototype = _.create(Shape.prototype, { 'constructor': Circle });
|
||||
*
|
||||
* var circle = new Circle;
|
||||
* circle instanceof Circle;
|
||||
* // => true
|
||||
*
|
||||
* circle instanceof Shape;
|
||||
* // => true
|
||||
*/
|
||||
function create(prototype, properties, guard) {
|
||||
var result = baseCreate(prototype);
|
||||
if (guard && isIterateeCall(prototype, properties, guard)) {
|
||||
properties = null;
|
||||
}
|
||||
return properties ? baseCopy(properties, result, keys(properties)) : result;
|
||||
}
|
||||
|
||||
export default create;
|
||||
Reference in New Issue
Block a user