_.create
语法:
_.create(prototype, [properties])
源代码链接:source
npm包链接:npm package
描述:
创建一个继承prototype
的对象。 如果提供了prototype
,它的可枚举属性会被分配到创建的对象上。
开始版本:2.3.0
参数:
prototype (Object)
: 要继承的对象。[properties] (Object)
: 待分配的属性。
返回值:
(Object)
: 返回新对象。
例子:
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
Last updated
Was this helpful?