- Notifications
You must be signed in to change notification settings - Fork230
Private and protected properties and methods#169
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
Closed
cortizg wants to merge4 commits intojavascript-tutorial:masterfromcortizg:es.javascript.info.1-09-04
Uh oh!
There was an error while loading.Please reload this page.
Closed
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
8 changes: 4 additions & 4 deletions1-js/09-classes/02-class-inheritance/1-class-constructor-error/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
8 changes: 4 additions & 4 deletions1-js/09-classes/02-class-inheritance/1-class-constructor-error/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
2 changes: 1 addition & 1 deletion1-js/09-classes/02-class-inheritance/2-clock-class-extended/solution.view/extended-clock.js
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
2 changes: 1 addition & 1 deletion1-js/09-classes/02-class-inheritance/2-clock-class-extended/source.view/index.html
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 |
|---|---|---|
| @@ -7,7 +7,7 @@ | ||
| clock.start(); | ||
| /*Tu clase debería funcionar así: */ | ||
| /* | ||
10 changes: 5 additions & 5 deletions1-js/09-classes/02-class-inheritance/2-clock-class-extended/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
68 changes: 1 addition & 67 deletions...09-classes/02-class-inheritance/3-class-extend-object/rabbit-extends-object.svg
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 26 additions & 26 deletions1-js/09-classes/02-class-inheritance/3-class-extend-object/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,81 +1,81 @@ | ||
| Primero, veamos por qué el último código no funciona. | ||
| La razón se vuelve obvia si tratamos de ejecutarlo. Un constructor de clase heredado debe llamar a`super()`.De lo contrario,`"this"`no se "definirá". | ||
| Así que aquí está la solución: | ||
| ```js run | ||
| class Rabbit extends Object { | ||
| constructor(name) { | ||
| *!* | ||
| super(); //necesita llamar alconstructorpadre al heredar | ||
| */!* | ||
| this.name = name; | ||
| } | ||
| } | ||
| let rabbit = new Rabbit("Rab"); | ||
| alert( rabbit.hasOwnProperty('name') ); //verdadero | ||
| ``` | ||
| Pero eso no es todo aún. | ||
| Incluso después de la solución, todavía hay una diferencia importante en`"class Rabbit extendsObjetc"` versus `class Rabbit`. | ||
| Como sabemos, la sintaxis"extends"configura dos prototipos: | ||
| 1.Entre el`"prototype"`de las funcionalidades del constructor (para métodos). | ||
| 2.Entre las funcionalidades propias del constructor (para métodos estáticos). | ||
| En nuestro caso, para `class Rabbit extends Object`significa:: | ||
| ```js run | ||
| class Rabbit extends Object {} | ||
| alert( Rabbit.prototype.__proto__ === Object.prototype ); // (1)verdadero | ||
| alert( Rabbit.__proto__ === Object ); // (2)verdadero | ||
| ``` | ||
| Entonces `Rabbit`ahora proporciona acceso a métodos estáticos de `Object`a través de`Rabbit`,como esto: | ||
| ```js run | ||
| class Rabbit extends Object {} | ||
| *!* | ||
| //normalmente llamamos Object.getOwnPropertyNames | ||
| alert ( Rabbit.getOwnPropertyNames({a: 1, b: 2})); // a,b | ||
| */!* | ||
| ``` | ||
| Pero si no tenemos `extend Object', entonces `Rabbit.__ proto__` no está configurado como `Object`. | ||
| Aqui la demostración: | ||
| ```js run | ||
| class Rabbit {} | ||
| alert( Rabbit.prototype.__proto__ === Object.prototype ); // (1)verdadero | ||
| alert( Rabbit.__proto__ === Object ); // (2)falso (!) | ||
| alert( Rabbit.__proto__ === Function.prototype ); //como cualquier función por defecto | ||
| *!* | ||
| // error, nohay tal función en Rabbit | ||
| alert ( Rabbit.getOwnPropertyNames({a: 1, b: 2})); // Error | ||
| */!* | ||
| ``` | ||
| Entonces `Rabbit`no proporciona acceso a métodos estáticos de 'Objeto' en ese caso. | ||
| Por cierto, `Function.prototype`tiene métodos de función "genéricos", como `call`, `bind` etc.En última instancia, están disponibles en ambos casos, porque para el constructor incorporado`Object`, `Object.__ proto__ === Function.prototype`. | ||
| Aqui está el gráfico: | ||
|  | ||
| Entonces, para resumir, hay dos diferencias: | ||
| | class Rabbit | class Rabbit extends Object | | ||
| |--------------|------------------------------| | ||
| | -- |necesita llamar a `super()`en el constructor | | ||
| | `Rabbit.__proto__ === Function.prototype` | `Rabbit.__proto__ === Object` | |
21 changes: 10 additions & 11 deletions1-js/09-classes/02-class-inheritance/3-class-extend-object/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.