3 ms·
Cool, this is neat. Here is a fuller usage example: var Rectangle = augment(Object, { constructor: function (width, height) { this.heig
by ivan_ah 13y ago
Cool, this is neat. Here is a fuller usage example:
var Rectangle = augment(Object, {
constructor: function (width, height) {
this.height = height;
this.width = width;
},
area: function () {
return this.width * this.height;
}
});
var Square = augment(Rectangle, {
constructor: function (side) {
Rectangle.call(this, side, side);
}
});
sq = new Square(3)
//augment.constructor {height: 3, width: 3, constructor: function, area: function}
// it will be a little annoying to see augment.constructor in the console
sq.width
// 3
sq.area()
// 9
Square.prototype
// Surrogate {constructor: function, area: function}
Square.constructor
// function Function() { [native code] }
sq instanceof Rectangle
//true