阅读(1298) (0)

Lodash _.create

2021-09-22 14:38:16 更新

_.create(prototype, [properties])

创建一个继承 prototype 的对象。 如果提供了 prototype,它的可枚举属性会被分配到创建的对象上。

添加版本

2.3.0

参数

  1. prototype (Object): 要继承的对象。
  2. [properties] (Object): 待分配的属性。

返回

(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