This allows you to dynamically change object definitions
|
We used function(constructor)
-
function car(make,model) { // An Example
-
this.make = make;
-
this.color = 'red';
-
this.model = model; }
-
mycar = new car("Ford","Explorer");
|
Suppose we wanted to add a new property 4wheelstatus
-
car.prototype.4wheelstatus = false;
-
mycar.4wheelstatus = true;
|
We can add methods with
-
function repaint(newcolor) {
-
car.prototype.repaint =repaint;
|
We can avoid repainting mycar by assigning
|
mycar.repaint = specialrepaint;
-
function specialrepaint(newcolor) {}
|