I am running the following in node.js:
function TextCell(text) {
this.text = text.split("\n");
}
TextCell.prototype.minWidth = function() {
return this.text.reduce(function(width, line) {
return Math.max(width, line.length);
}, 0);
};
TextCell.prototype.minHeight = function() {
return this.text.length;
};
TextCell.prototype.draw = function(width, height) {
var result = [];
for (var i = 0; i < height; i++) {
var line = this.text[i] || "";
result.push(line + repeat(" ", width - line.length));
}
return result;
};
function RTextCell(text) {
TextCell.call(this, text);
}
RTextCell.prototype = Object.create(TextCell.prototype);
RTextCell.prototype.draw = function(width, height) {
var result = [];
for (var i = 0; i < height; i++) {
var line = this.text[i] || "";
result.push(repeat(" ", width - line.length) + line);
}
return result;
};
When I console.log(RTextCell.prototype), I get a prototype with only the draw function. Also, when I log(Object.create(Textcell.prototype)) I just get "TextCell{}". Why does it seem like the clone of the prototype is empty?
EDIT: I noticed my mistake. I made objects of type RTextCell before defining it. That's why the prototype turned out empty. Sorry for not including that part here
__proto__property to see the underlying prototype.