Lodash _.create

2021-09-23 09:35 更新

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


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号