01
Using the this keyword in the constructor function or class, Person,
will allow us to add the method as a properties/attributes to the 'instance' of Person me
function Person(){
this.talk = function(){
return 'Talking'
}
}
const me = new Person()
me
The this keeps the talk method in the instance and
not in it's Person prototype
02
The talk() method is now stored as an attribute to the instance me
of parent class/funciton Person.
me.__proto__
Person.prototype
Person
The method is not longer stored in prototype or __proto
03
We don't use this frequently b/c it
will copy the function into each instance of the class, is not needed
Here, we see that when using this in the 'Prototype' class Person
if will appear as undefined when logged, that is b/c as we have said this whole page...
function Person(){ this.age = 12 } const me = new Person() me.age
Person.age
The this atrribute, age and its value get applied to the 'instance' of the class and not
to the class itself