Lodash - create 方法
语法
_.create(prototype, [properties])
创建一个从原型对象继承的对象。如果给出属性对象,则创建的对象将被分配其自身可枚举字符串键属性。
参数
prototype (对象) − 要继承的对象。
[properties] (对象) − 要分配给对象的属性。
输出
(对象) − 返回新对象。
示例
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);
将上述程序保存在 tester.js 中。运行以下命令来执行此程序。
命令
\>node tester.js
输出
true true
lodash_object.htm
广告