Lodash - create method



Syntax

_.create(prototype, [properties])

Creates an object that inherits from the prototype object. If a properties object is given, its own enumerable string keyed properties are assigned to the created object.

Arguments

  • prototype (Object) − The object to inherit from.

  • [properties] (Object) − The properties to assign to the object.

Output

  • (Object) − Returns the new object.

Example

var _ = require('lodash');
function Shape() {
   this.x = 0;
   this.y = 0;
}
function Circle() {
   Shape.call(this);
}
Circle.prototype = _.create(Shape.prototype, {
   'constructor': Circle
});
 
var circle = new Circle;

console.log(circle instanceof Circle);
console.log(circle instanceof Shape);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

true
true
lodash_object.htm
Advertisements