Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b644b4

Browse files
authored
Merge pull request HackYourFuture#35 from remarcmij/master
MAKEME week 7, README Week 1 + prototype chain
2 parents 967815d + 04d9f20 commit 5b644b4

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

Week1/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ Only watch the below chapters:
3333

3434
- The 50 best websites to Learn JavaScript: http://www.codeconquest.com/blog/top-50-websites-to-learn-javascript/
3535

36-
:star: You can also already go through the [review](/Week2/REVIEW.md) of the upcoming lecture. :star:
36+
:star: You can also already go through the topics of the upcoming lecture. :star:
37+
38+
- Intro JavaScript (What is it, where can you use it for)
39+
- [Variables (var, let, const)](../fundamentals/variables.md)<br>
40+
- [Basic Data types (Strings, Numbers, Arrays, Booleans)](../fundamentals/values.md)<br>
41+
- [Operators](../fundamentals/operators.md)<br>
42+
- [Naming conventions](../fundamentals/naming_conventions.md)
3743

3844
_Please go through the material and come to class prepared!_
3945

Week7/MAKEME.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ myMovie.addStar(firstActor);
125125
// Make sure that the following actions work.
126126
console.log(myMovie.getStars().map(actor => `${actor.getName()} ${actor.getAge()}`));
127127
const director = myMovie.getDirector();
128-
console.log(`Director: ${director.map(director => `${director.getName()}`)}`);
128+
console.log(`Director: ${director.getName()}`);
129129
```
130130

131131
Fun extra step: If you get bored, template them and make a page by rendering the results in HTML :smile: with something like `document.querySelector('.move').innerHTML = ...`

fundamentals/oop_classes.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,38 @@ months
214214
```
215215

216216

217-
The diagram below depicts how this sharing works out. At this time it is not necessary that you understand every detail. Just note how there is a single copy of functions, shared by all instances of the `Months` objects.
218-
219217
![prototype](assets/prototype.png)
220218

219+
### Prototype vs __prototype
220+
221+
The above diagram depicts how this sharing works out.
222+
223+
The `prototype` property exists on all functions but is only relevant when that function is used as a **constructor function**. By assigning methods to the `prototype` property you are basically defining a ‘prototype’ object that will be shared by all objects created through the constructor function when called in conjunction with the `new` keyword.
224+
225+
In contrast to `prototype`, the `__proto__` property (in documentation sometimes denoted as `[[proto]]`) is a property that exist on objects created through the constructor function. This `__proto__` property points to the shared ‘prototype’ object, as defined on the constructor function’s `prototype` property.
226+
227+
The prototype object itself also has a `__proto__` property. In most cases this property points to the prototype of the standard JavaScript `Object` prototype. This is because, ultimately, all objects in JavaScript are prototype-linked to the `Object` prototype. In OOP terms one would say that all JavaScript objects ultimately derive from `Object`.
228+
229+
The `__proto__` property of the `Object` prototype itself has the value `null`. This signals the end of the prototype chain.
230+
231+
When you call a method on an object that does not exist on the object itself, the JavaScript engine will 'walk' down the prototype chain until it finds the requested method _or_ until it reaches the end of the chain.
232+
233+
If the method is found, JavaScript calls the method, setting its `this` value to the object the method was called on. This happens behind the scenes without requiring intervention from the programmer.
234+
235+
If the method was not found by walking the prototype chain, a run-time error is produced, e.g:
236+
237+
```js
238+
myObj.someNonExistingMethod();
239+
240+
```
241+
242+
```
243+
myObj.someNonExistingMethod();
244+
^
245+
246+
TypeError: myObj.someNonExistingMethod is not a function
247+
```
248+
221249
### ES6 Classes
222250

223251
In ES6 a new way of defining objects and its methods was introduced. It uses the same `prototype` mechanism behind the scenes, but its syntax is closer to that of other object-oriented languages, such as Java, etc. Because it is only new syntax, hiding the intricacies of the `prototype`, it is often designated as 'syntactic sugaring'.
@@ -312,4 +340,5 @@ Array.prototype.myFilter = function (callback) {
312340
}
313341
return arr;
314342
};
315-
```
343+
```
344+

0 commit comments

Comments
 (0)