I know two ways to inherit function constructor.
Option 1 Object.create
function x(x, y) {
this.x = x;
this.y = y;
}
x.prototype.XDD = function() {};
function y(c, r) {
x.call(this, 1, 2);
this.r = r;
this.c = c;
}
y.prototype = Object.create(x.prototype);
y.prototype.YDD = function() {};
y.prototype.XDD = function() {};
y.prototype.constructor = y;
var rect = new y(1, 2);
Option 2 Object.setPrototypeOf()
function x(x, y) {
this.x = x;
this.y = y;
}
x.prototype.XDD = function() {};
function y(c, r) {
x.call(this, 1, 2);
this.r = r;
this.c = c;
}
y.prototype.YDD = function() {};
y.prototype.XDD = function() {};
Object.setPrototypeOf(y.prototype, x.prototype);
var rect = new y(1, 2);
What are the differences between them ?.And there is another solution better than these ?.