[js] fix prototypal inheritance question from "prototype" to "__proto__" (#240)

* Changed object prototype reference from "prototype" to "__proto__"

* Update javascript-questions.md

Co-authored-by: Yangshun Tay <tay.yang.shun@gmail.com>
This commit is contained in:
Slava 2020-03-07 10:07:47 +02:00 committed by GitHub
parent 4954c34ff0
commit f5169836a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -97,7 +97,7 @@ ES6 allows you to use [arrow functions](http://2ality.com/2017/12/alternate-this
### Explain how prototypal inheritance works
This is an extremely common JavaScript interview question. All JavaScript objects have a `prototype` property, that is a reference to another object. When a property is accessed on an object and if the property is not found on that object, the JavaScript engine looks at the object's `prototype`, and the `prototype`'s `prototype` and so on, until it finds the property defined on one of the `prototype`s or until it reaches the end of the prototype chain. This behavior simulates classical inheritance, but it is really more of [delegation than inheritance](https://davidwalsh.name/javascript-objects).
This is an extremely common JavaScript interview question. All JavaScript objects have a `__proto__` property, that is a reference to another object, which is called the object's "prototype". When a property is accessed on an object and if the property is not found on that object, the JavaScript engine looks at the object's `__proto__`, and the `__proto__`'s `__proto__` and so on, until it finds the property defined on one of the `__proto__`s or until it reaches the end of the prototype chain. This behavior simulates classical inheritance, but it is really more of [delegation than inheritance](https://davidwalsh.name/javascript-objects).
#### Example of Prototypal Inheritance
@ -176,6 +176,7 @@ c.constructor.name;
###### References
- http://dmitrysoshnikov.com/ecmascript/javascript-the-core/
- https://www.quora.com/What-is-prototypal-inheritance/answer/Kyle-Simpson
- https://davidwalsh.name/javascript-objects
- https://crockford.com/javascript/prototypal.html