You can't do this. What you can do is change the prototype later. This will, however, only effect instances that don't have that property defined:
var Bike = function(speed){
if(speed) {
this.speed = speed;
}
};
Bike.prototype.speed = 100;
var suzuki = new Bike(500);
var hayabusa = new Bike();
var honda = new Bike();
console.log(suzuki.speed); //500
console.log(hayabusa.speed); //100
console.log(honda.speed); //100
Bike.prototype.speed = 200;
console.log(suzuki.speed); //500
console.log(hayabusa.speed); //200
console.log(honda.speed); //200
The only way to change all instances is actually to change all instances. But you could do something like saving the date when you set the property, and the date on the property of the prototype and define a getter that is doing what you want:
var Bike = function(speed){
Object.defineProperty(this, 'speed', {
get() {
if(this.speedMoment && this.speedMoment > Bike.speedMoment) {
return this._speed;
} else {
return Bike._speed;
}
},
set(val) {
Bike._speedMomentIter++;
this.speedMoment = Bike._speedMomentIter;
this._speed = val;
}
});
if(speed) {
this.speed = speed;
}
};
Bike._speedMomentIter = 0;
Object.defineProperty(Bike, 'speed', {
set(val) {
Bike._speedMomentIter++;
this.speedMoment = Bike._speedMomentIter;
this._speed = val;
}
});
Bike.speed = 100;
var suzuki = new Bike(500);
var hayabusa = new Bike(800);
var honda = new Bike();
console.log(suzuki.speed); //500
console.log(hayabusa.speed); //800
console.log(honda.speed); //100
Bike.speed = 200;
console.log(suzuki.speed); //200
console.log(hayabusa.speed); //200
console.log(honda.speed); //200