Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3
F.prototype#178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
F.prototype#178
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
12 changes: 6 additions & 6 deletions1-js/08-prototypes/02-function-prototype/1-changing-prototype/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
Odpovědi: | ||
1. `true`. | ||
Přiřazení do `Králík.prototype`nastaví`[[Prototype]]`pro nové objekty, ale neovlivní již existující. | ||
2. `false`. | ||
Objekty jsou přiřazovány odkazem. Objekt z `Králík.prototype`není duplikován, ale je to stále jediný objekt, na který se odkazují jak `Králík.prototype`, tak`[[Prototype]]`objektu `králík`. | ||
Když tedy změníme jeho obsah skrz jeden odkaz, uvidíme to i druhým odkazem. | ||
3. `true`. | ||
Všechny operace`delete`se aplikují přímo na objekt. Zde se`deletekrálík.žere` pokusí odstranit vlastnost `žere` z objektu `králík`,ale ten ji neobsahuje. Operace tedy nemá žádný účinek. | ||
4. `undefined`. | ||
Vlastnost `žere` je smazána z prototypu a nadále neexistuje. |
72 changes: 36 additions & 36 deletions1-js/08-prototypes/02-function-prototype/1-changing-prototype/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
50 changes: 25 additions & 25 deletions1-js/08-prototypes/02-function-prototype/4-new-object-same-constructor/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
Tento přístup můžeme použít, pokud jsme si jisti, že vlastnost `"constructor"`obsahuje správnou hodnotu. | ||
Například pokud se nedotkneme standardní vlastnosti`"prototype"`,pak bude tento kód zaručeně fungovat: | ||
```js run | ||
functionUživatel(jméno) { | ||
this.jméno =jméno; | ||
} | ||
letuživatel = newUživatel('Jan'); | ||
letuživatel2 = newuživatel.constructor('Petr'); | ||
alert(uživatel2.jméno ); //Petr (funguje!) | ||
``` | ||
Funguje to, protože `Uživatel.prototype.constructor ==Uživatel`. | ||
...Ale pokud někdo dejme tomu přepíše `Uživatel.prototype`a zapomene znovu vytvořit `constructor`, aby odkazoval na `Uživatel`,pak to selže. | ||
Například: | ||
```js run | ||
functionUživatel(jméno) { | ||
this.jméno =jméno; | ||
} | ||
*!* | ||
Uživatel.prototype = {}; // (*) | ||
*/!* | ||
letuživatel = newUživatel('Jan'); | ||
letuživatel2 = newuživatel.constructor('Petr'); | ||
alert(uživatel2.jméno ); // undefined | ||
``` | ||
Proč je `uživatel2.jméno` `undefined`? | ||
Takto funguje `newuživatel.constructor('Petr')`: | ||
1.Nejprve hledá`constructor`v objektu `uživatel`.Nic. | ||
2.Pak postupuje řetězcem prototypů. Prototyp objektu `uživatel` je `Uživatel.prototype` a ani ten nemá žádný `constructor` (protože jsme ho „zapomněli“ správně nastavit!). | ||
3.Postupuje řetězcem dále nahoru. `Uživatel.prototype`je planý objekt a jeho prototypem je vestavěný `Object.prototype`. | ||
4.Nakonec pro vestavěný`Object.prototype` je vestavěný`Object.prototype.constructor == Object`.Ten se tedy použije. | ||
Nakonec tedy máme`letuživatel2 = new Object('Petr')`. | ||
To pravděpodobně není to, co chceme. Rádi bychom vytvořili`newUživatel`,ne `new Object`.To je důsledek chybějící vlastnosti `constructor`. | ||
(Jen pro případ, že vás to zajímá: volání`new Object(...)`konvertuje svůjargumentna objekt. To je teoretická záležitost, v praxi nikdo nevolá`new Object`s hodnotou a obecně vůbec nepoužíváme`new Object`k vytváření objektů.) |
8 changes: 4 additions & 4 deletions1-js/08-prototypes/02-function-prototype/4-new-object-same-constructor/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.