主题
create
js
_.create(prototype, [properties])
创建一个从 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.
新增于
¥Since
2.3.0
参数
¥Arguments
prototype
(对象):要继承的对象。¥
prototype
(Object): The object to inherit from.[properties]
(对象):要分配给对象的属性。¥
[properties]
(Object): The properties to assign to the object.
返回
¥Returns
(对象):返回新对象。
¥(Object): Returns the new object.
示例
¥Example
js
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