Lodash教程

Lodash create method

语法

_.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.

参数

prototype (Object) − The object to inherit from. [properties] (Object) − The properties to assign to the object.

输出

(Object) − Returns the new object.

实例

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

输出

true
true
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4