time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

create.js (1032B)


      1 var baseAssign = require('./_baseAssign'),
      2     baseCreate = require('./_baseCreate');
      3 
      4 /**
      5  * Creates an object that inherits from the `prototype` object. If a
      6  * `properties` object is given, its own enumerable string keyed properties
      7  * are assigned to the created object.
      8  *
      9  * @static
     10  * @memberOf _
     11  * @since 2.3.0
     12  * @category Object
     13  * @param {Object} prototype The object to inherit from.
     14  * @param {Object} [properties] The properties to assign to the object.
     15  * @returns {Object} Returns the new object.
     16  * @example
     17  *
     18  * function Shape() {
     19  *   this.x = 0;
     20  *   this.y = 0;
     21  * }
     22  *
     23  * function Circle() {
     24  *   Shape.call(this);
     25  * }
     26  *
     27  * Circle.prototype = _.create(Shape.prototype, {
     28  *   'constructor': Circle
     29  * });
     30  *
     31  * var circle = new Circle;
     32  * circle instanceof Circle;
     33  * // => true
     34  *
     35  * circle instanceof Shape;
     36  * // => true
     37  */
     38 function create(prototype, properties) {
     39   var result = baseCreate(prototype);
     40   return properties == null ? result : baseAssign(result, properties);
     41 }
     42 
     43 module.exports = create;