-
-
Notifications
You must be signed in to change notification settings - Fork 112
Native prototypes #233
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native prototypes #233
Changes from 2 commits
0f761e8
e994eaf
52dcc16
cfa5101
c836a26
4770f5f
86e78a1
1fdbd84
c1fc6cf
209f35c
7961a93
1a0745c
197c4f2
926a671
aa5ca52
54b79a7
2b35857
fa8bf24
8842a59
2d40fdd
06ba0db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,33 +1,33 @@ | ||||||
| # Native prototypes | ||||||
| # Protótipos Nativos | ||||||
|
|
||||||
| The `"prototype"` property is widely used by the core of JavaScript itself. All built-in constructor functions use it. | ||||||
| A propriedade `"prototype"` é comumente utilizada pelo núcleo do próprio JavaScript. Toda função construtora embutida a usa. | ||||||
|
||||||
| A propriedade `"prototype"` é comumente utilizada pelo núcleo do próprio JavaScript. Toda função construtora embutida a usa. | |
| A propriedade `"prototype"` é muito utilizada pelo núcleo do próprio JavaScript. Toda a função construtora embutida (*built-in*) a usa. |
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Onde está o código que gera a string `"[object Object]"`? Isso é um método embutido `toString`, mas onde ele está? O `obj` está vazio! | |
| Onde está o código que gera a string `"[object Object]"`? Isto vem de um método embutido `toString`, mas onde ele está? O `obj` está vazio! |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ... Mas a notação abreviada `obj = {}` é o mesmo que `obj = new Object()`, onde `Object` é uma função construtora embutida, com seu próprio `prototype` referenciando um objeto enorme com `toString` e outros métodos. | |
| ... A notação abreviada `obj = {}` é o mesmo que `obj = new Object()`. Onde `Object` é uma função construtora embutida, com o seu próprio `prototype` referenciando um objeto enorme, possuindo `toString` e outros métodos. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Quando `new Object()` é chamado (ou um objeto literal `{...}` é criado), o seu `[[Prototype]]` é configurado para o `Object.prototype` de acordo com a regra que nós discutimos no capítulo anterior: | |
| Quando `new Object()` é invocado (ou um objeto literal `{...}` é criado), o seu `[[Prototype]]` é configurado para o `Object.prototype`, de acordo com a regra que nós discutimos no capítulo anterior: |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Note que não há um `[[Prototype]]` adicional na cadeia acima de `Object.prototype`: | |
| Note que na cadeia, acima de `Object.prototype`, não há um `[[Prototype]]` adicional: |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Outros objetos embutidos, como `Array`, `Date`, `Function`, entre outros, também mantém métodos nos seus protótipos. | |
| Outros objetos embutidos, como `Array`, `Date`, `Function`, etc., também têm métodos nos seus protótipos. |
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // e depois herda de Object.prototype? | |
| // a seguir herda de Object.prototype? |
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Outros objetos embutidos também trabalham da mesma forma. Até mesmo funções -- elas são objetos de um construtor `Function` embutido, e seus métodos (`call`/`apply` e outros) são obtidos de `Function.prototype`. Funções também têm seu próprio `toString`. | |
| Outros objetos embutidos também trabalham da mesma forma. Até mesmo funções -- elas são objetos de um construtor `Function` embutido, e os seus métodos (`call`/`apply`, e outros) são obtidos de `Function.prototype`. Funções também têm o seu próprio `toString`. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Como sabemos, eles não são objetos. Mas se nós tentarmos acessar as propriedades deles, temporariamente são criados objetos que contém os construtores embutidos `String`, `Number` and `Boolean`. Eles fornecem os métodos e disaparecem. | |
| Como sabemos, eles não são objetos. Mas se nós tentarmos acessar as propriedades deles, temporariamente são criados objetos usando os construtores embutidos `String`, `Number` and `Boolean`. Esses objetos fornecem os métodos e desaparecem. |
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Protótipos são globais, então é fácil gerar um conflito. Se duas bibliotecas adicionam um método `String.prototype.show`, uma delas estará sobrescrevendo a outra. | |
| Protótipos são globais, então é fácil gerar um conflito. Se duas bibliotecas adicionam um método `String.prototype.show`, aí uma delas estará sobrescrevendo a outra. |
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
flaviohblima marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - O objeto só guarda os dados nele mesmo (itens de array, propriedades de objetos, a data) | |
| - O objeto só guarda os dados nele mesmo (itens de array, propriedades de objetos, uma data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.