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
廣告