I don't understand which variants of inheritance we should use. I even don't know if there is a difference between them.
I have a simple JavaScript inheritance example:
function MyObject(a){
this.a = a;
}
function MyObjectChild(a, b){
MyObject.call(this, a);
this.b = b;
}
MyObjectChild.prototype = Object.create(MyObject.prototype);
var myObj = new MyObjectChild(1, 2);
console.log(myObj.a + " " + myObj.b);
result will be "1 2".
But this row:
MyObjectChild.prototype = Object.create(MyObject.prototype);
we can write in 10 different ways:
MyObjectChild.prototype = new MyObject();
MyObjectChild.prototype = MyObject.prototype;
MyObjectChild.prototype = MyObject.prototype.prototype;
MyObjectChild.prototype = Object.create(MyObject);
MyObjectChild.prototype = Object.create(MyObject.prototype);
MyObjectChild.prototype.prototype = new MyObject();
MyObjectChild.prototype.prototype = MyObject.prototype;
MyObjectChild.prototype.prototype = MyObject.prototype.prototype;
MyObjectChild.prototype.prototype = Object.create(MyObject);
MyObjectChild.prototype.prototype = Object.create(MyObject.prototype);
All of them will work! Can somebody explain which variants we should use and which one we should not?