en.javascript.info/1-js/08-prototypes/01-prototype-inheritance
Mustafa Kemal Tuna 7d0d65478d
clarifying example code
An interesting question may arise in the example above: what’s the value of this inside set fullName(value)? Where are the properties this.name and this.surname written: into user or admin?

The answer is simple: this is not affected by prototypes at all.

No matter where the method is found: in an object or its prototype. In a method call, this is always the object before the dot.

So, the setter call admin.fullName= uses admin as this, not user.

That is actually a super-important thing, because we may have a big object with many methods, and have objects that inherit from it. And when the inheriting objects run the inherited methods, they will modify only their own states, not the state of the big object.

The example code doesn't show these concepts. Also, these additions can make readers ask questions before the explanation of the example code.
2020-07-25 05:38:45 +03:00
..
1-property-after-delete refactor classes, add private, minor fixes 2019-03-05 18:44:28 +03:00
2-search-algorithm Update task.md 2019-10-21 11:43:39 +02:00
3-proto-and-this Update task.md 2019-10-21 11:48:46 +02:00
4-hamster-proto Update task.md 2019-10-21 11:52:48 +02:00
article.md clarifying example code 2020-07-25 05:38:45 +03:00
object-prototype-empty.svg re-import images from Sketch (no changes) 2019-10-10 17:08:16 +03:00
proto-animal-rabbit-chain.svg re-import images from Sketch (no changes) 2019-10-10 17:08:16 +03:00
proto-animal-rabbit-walk-2.svg re-import images from Sketch (no changes) 2019-10-10 17:08:16 +03:00
proto-animal-rabbit-walk-3.svg re-import images from Sketch (no changes) 2019-10-10 17:08:16 +03:00
proto-animal-rabbit-walk.svg re-import images from Sketch (no changes) 2019-10-10 17:08:16 +03:00
proto-animal-rabbit.svg re-import images from Sketch (no changes) 2019-10-10 17:08:16 +03:00
proto-user-admin.svg re-import images from Sketch (no changes) 2019-10-10 17:08:16 +03:00
rabbit-animal-object.svg re-import images from Sketch (no changes) 2019-10-10 17:08:16 +03:00