2016-01-28 01:16:24 -08:00
|
|
|
define(['./_baseAssign', './_baseCreate'], function(baseAssign, baseCreate) {
|
2015-12-16 17:52:15 -08:00
|
|
|
|
2015-01-08 00:37:01 -08:00
|
|
|
/**
|
2016-03-26 00:00:01 -07:00
|
|
|
* Creates an object that inherits from the `prototype` object. If a
|
2016-04-07 21:35:23 -07:00
|
|
|
* `properties` object is given, its own enumerable string keyed properties
|
2016-03-26 00:00:01 -07:00
|
|
|
* are assigned to the created object.
|
2015-01-08 00:37:01 -08:00
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf _
|
2016-03-26 00:00:01 -07:00
|
|
|
* @since 2.3.0
|
2015-01-08 00:37:01 -08:00
|
|
|
* @category Object
|
|
|
|
|
* @param {Object} prototype The object to inherit from.
|
|
|
|
|
* @param {Object} [properties] The properties to assign to the object.
|
|
|
|
|
* @returns {Object} Returns the new object.
|
|
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* function Shape() {
|
|
|
|
|
* this.x = 0;
|
|
|
|
|
* this.y = 0;
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* function Circle() {
|
|
|
|
|
* Shape.call(this);
|
|
|
|
|
* }
|
|
|
|
|
*
|
2015-12-16 17:46:57 -08:00
|
|
|
* Circle.prototype = _.create(Shape.prototype, {
|
|
|
|
|
* 'constructor': Circle
|
|
|
|
|
* });
|
2015-01-08 00:37:01 -08:00
|
|
|
*
|
|
|
|
|
* var circle = new Circle;
|
|
|
|
|
* circle instanceof Circle;
|
|
|
|
|
* // => true
|
|
|
|
|
*
|
|
|
|
|
* circle instanceof Shape;
|
|
|
|
|
* // => true
|
|
|
|
|
*/
|
2015-12-16 17:53:20 -08:00
|
|
|
function create(prototype, properties) {
|
2015-01-08 00:37:01 -08:00
|
|
|
var result = baseCreate(prototype);
|
2016-10-30 20:06:57 -07:00
|
|
|
return properties == null ? result : baseAssign(result, properties);
|
2015-01-08 00:37:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return create;
|
|
|
|
|
});
|