I don't seem to understand the difference between assigning one constructor prototype to an other, and using Object.create. can anyone provide an example of the difference?
I've created this inheritance example which provides the same result for both cases:
function MyObject() {
}
function O1() {
MyObject.call(this);
}
O1.prototype = MyObject.prototype;
function O2() {
MyObject.call(this);
}
O2.prototype = Object.create(MyObject.prototype);
In your example,
Object.create
just creates one mode (superfluous) object. If you createnew O1
andnew O2
, their inheritance diagram will be this: