Apuntes Javascript Avanzado
Nivel Avanzado
JuanMa Garrido
Este libro está a la venta en http://leanpub.com/apuntes-javascript-avanzado
Esta versión se publicó en 2015-01-30
This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing
process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools
and many iterations to get reader feedback,pivot until you have the right book and build
traction once you do.
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0
Unported License
A mi abuelo…
“Hijo, tu di que si, y luego haz lo que te de la gana” (mi abuelo)
Índice general
1. Prologo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.1 Referencias . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Agradecimientos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1
1
2. Same-origin policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1 JSONP vs CORS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
2
3. JSONP . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . .
3.1 Peticiones JSONP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
5
4. CORS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.1 Peticiones CORS sencillas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8
8
5. El valor de this . . . . . . . . . . . . . . .
5.1 En unafunción global . . . . . . . . .
5.2 En un método de un objeto . . . . . .
5.3 En un metodo de un prototipo . . . .
5.4 En una función constructora . . . . .
5.5 Utilizando call o apply . . . . . . . .
5.6 Utilizando bind . . . . . . . . . . . .
5.7 En una función asociada a un evento
.
.
.
.
.
.
.
.
9
9
10
11
11
12
13
13
6. Prototype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . .
15
7. Herencia . . . . . . . . . . . . . . . . . . . . . . . . . .
7.1 Encadenamiento de Prototipos (Prototype Chaining)
7.2 Moviendo metodos re-utilizables al prototypo . . . .
7.3 Herencia sólo del prototipo . . . . . . . . . . . . . .
7.4 Función constructora temporal F() . . . . . . . . . .
7.5 Encapsulando la herencia en una función . . . . . .
7.6 Robando elconstructor . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
22
22
24
26
27
29
30
8. Contexto de Ejecución . . . . . . . . . .
8.1 Objeto Variable (Variable Object) .
8.2 Fases deProcesamiento del Código
8.3 Tipos de Funciones . . . . . . . . .
8.4 Hoisting . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
32
32
35
37
39
9. Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
..
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
ÍNDICE GENERAL
9.1
Ciclo de vida de una Función . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
10.Patrones de Código . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.1 Separación de capas . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.2 Namespaces . . . . ....
Regístrate para leer el documento completo.