01
The pervious might lesson be wrong about __proto__, as you can see the Person
class .prototype but the instance me has the attribute __proto__
So figure out,
- difference between
__proto__and.prototypeor[[Prototype]] - if __proto__ is 'depricated'
Note, both contain the methods of the class
class Person {
talk(){
return 'Talking'
}
}
const me = new Person()
me.__proto__
Person.prototype == me.__proto__
02
We will use __proto__ on instances of classes until we learn otherwise,
as you can see Perosn.prototype ==
me.__proto__
is true
class Person { talk(){ return 'talking' } } const me = new Person() Person.prototype == me.__proto__
03
The methods reside in .prototyp and .__proto__.
class Person {
talk(){
return 'Talking'
}
}
const me = new Person()
Person.prototype.talk
me.__proto__.talk
04
I think if you alter the method of an instance like me
in it's __proto__ it changes the talk()
method in the Person class prototype
where the methods
class Person { talk(){ return 'Talking' } } const me = new Person()
me.__proto__.talk = () => { return 'new talking instance' }
Person.prototype.talk
Notice how the Person class .prototye method
of talking when the .__proto__ talk() method is changed to
return 'new talking method'
05
Summary of this part of tutorial is
- that
__proto__is still used, - is methods changed in
__proto__of an instance, it will also change the method of the parent class like thetalk()method inPerson.prototype