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
输出