Given the following code:
var Car = function() {};
Car.prototype = {
wheels: {
rims: 'steel'
}
}
var volvo = new Car;
var mercedes = new Car;
volvo.wheels.rims = 'aluminium';
console.log(volvo.wheels.rims, mercedes.wheels.rims); // 'aluminium', 'aluminium'
Can you explain why instance mercedes
of Auto
automatically inherits the sub-property definition for rims
from volvo
?
Note the following code works as expected with same setup:
volvo.wheels = 4;
console.log(volvo.wheels, mercedes.wheels); // 4, Object { rims: 'steel' }