function person(name){
this.name = name;
This.prof=function(){
console.log("name:"+this.name+"\nage:"+this.age+"\ncolor:"+this.color+"\nweight:"+this.weight);
}
}
person.prototype.color="red";
person.prototype.age="18";
varman = new person("Jackbow");
man.weight = 50;
man.prof();
This man.weight=50;
is
man={
weight —50
};
Why shouldn't I?
javascript
{
weight —50
}
This statement creates an object with only the weight
property.This object has nothing to do with man
or person
.So,
man={
weight —50
};
The new object replaces the entire man
content.
man.weight=50;
If you write , only the weight
property changes, so it does not affect other properties or the prototype chain.
© 2024 OneMinuteCode. All rights reserved.