Skip to content

Commit e7c00d8

Browse files
committed
Merge pull request BonsaiDen#118 from julionc/master
[es] Spanish translation
2 parents 1484fbf + f1a5f8c commit e7c00d8

25 files changed

+2008
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
/site/tr
1313
/site/ko
1414
/site/ja
15+
/site/es
1516
*.md~
1617
*.src.md

doc/es/array/constructor.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## El constructor `Array`
2+
3+
Desde el constructor `Array` es ambiguo en la forma en que ocupa sus párametros,
4+
es recomendable siempre el uso de arrays literales - la notación `[]` -
5+
cuando se crean nuevos arrays.
6+
7+
[1, 2, 3]; // Resultado: [1, 2, 3]
8+
new Array(1, 2, 3); // Resultado: [1, 2, 3]
9+
10+
[3]; // Resultado: [3]
11+
new Array(3); // Resultado: []
12+
new Array('3') // Resultado: ['3']
13+
14+
En casos cuando sólo hay un argumento pasado al constructor del `Array`,
15+
y que el argumento es un `Número`, el contructor devolverá un array *disperso*
16+
con la propiedad `length` establecida al valor del argumento. Esto debe señalarse
17+
que la propiedad `length` **sólo** del nuevo array se establecerá de esa manera,
18+
los índices reales de la matriz no se iniciará.
19+
20+
var arr = new Array(3);
21+
arr[1]; // undefined
22+
1 in arr; // falso, el índice no se ha establecido
23+
24+
El comportamiento de poder establecer la longitud de un array inicial sólo es útil
25+
en algunos casos array, como la repetición de una cadena, en la que se evita el uso
26+
del código de `bucle for`.
27+
28+
new Array(count + 1).join(stringToRepeat);
29+
30+
### En conclusión
31+
32+
El uso de un constructor `Array` debe ser devuelto como sea posible.
33+
Los literales son definitivamente preferidos. Estos son más cortos y tienen una
34+
sintaxis más limpia; por lo tanto, también se incrementa la legibilidad del código.
35+

doc/es/array/general.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
## Iteración de un Array y sus propiedades
2+
3+
A pesar que los arrays en JavaScript son objetos, no existe un buena razón para
4+
usarlo en un [`bucle for`](#object.forinloop) para una interación de este. De
5+
hecho, hay un número de buenas razones **contra** el uso de `for in` en arrays.
6+
7+
> **Nota:** Los arrays de JavaScript **no** son *arrays asociativos*. JavaScript sólo
8+
> tiene [objetos](#object.general) para el mapeo de keys a valores. Y mientras
9+
> que los arrays asociativos **preservan** el orden, los objetos **no**.
10+
11+
Dado que el bucle `for in` enumera todas las propiedades que están en una cadena
12+
de prototipo y la única manera para excluir estas propiedades es el uso de
13+
[`hasOwnProperty`](#object.hasownproperty), ya que es **veinte veces** más
14+
lento que un bucle `for` normal.
15+
16+
### Iteración
17+
18+
Con el fin de obtener el mejor rendimiento cuando se repite la interación de arrays,
19+
es lo mejor hacer uso del clásico bucle `for`.
20+
21+
var list = [1, 2, 3, 4, 5, ...... 100000000];
22+
for(var i = 0, l = list.length; i < l; i++) {
23+
console.log(list[i]);
24+
}
25+
26+
Hay una captura adicional en el ejemplo anterior, que es el almacenamiento de la
27+
caché de longitud del array vía `l = list.length`.
28+
29+
Aunque la propiedad `length` es definida en el mismo array, todavía posee una sobrecarga
30+
para realizar la búsqueda en cada interación del bucle. Y mientras que los últimos
31+
motores de JavaScript **pueden** aplicar optimizaciones en este caso, no hay manera
32+
de saber si el ćodigo se ejecutará en uno de estos nuevos motores nuevos o no.
33+
34+
De hecho, dejando de lado el alamacenamiento en caché puede resultar que el bucle
35+
inicie sólo la **mitad de rápido** que con la longitud de la caché.
36+
37+
### La propiedad `length`
38+
39+
Mientras que *getter* de la propiedad `length` simplemente retorne el número de
40+
elementos son contenidos en un array, el *setter* puede ser usado para
41+
**truncar** el array.
42+
43+
var foo = [1, 2, 3, 4, 5, 6];
44+
foo.length = 3;
45+
foo; // [1, 2, 3]
46+
47+
foo.length = 6;
48+
foo; // [1, 2, 3]
49+
50+
La asignación de un menor número de longitud trunca al array, pero incrementando la
51+
longitud no tiene ningún efecto sobre el array.
52+
53+
### En conclusión
54+
55+
Para obtener el mejor rendimiento es recomendable siempre usar el bucle `for`
56+
y alamacenar en caché la propiedad `length`. El uso del bucle `for in` en un array
57+
es señal de un código mal escrito propenso a errores y un mal desempeño.
58+

doc/es/core/delete.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
## The `delete` Operator
2+
3+
In short, it's *impossible* to delete global variables, functions and some other
4+
stuff in JavaScript which have a `DontDelete` attribute set.
5+
6+
### Global code and Function code
7+
8+
When a variable or a function is defined in a global
9+
or a [function scope](#function.scopes) it is a property of either
10+
Activation object or Global object. Such properties have a set of attributes,
11+
one of these is `DontDelete`. Variable and function declarations in global
12+
and function code always create properties with `DontDelete`, therefore
13+
cannot be deleted.
14+
15+
// global variable:
16+
var a = 1; // DontDelete is set
17+
delete a; // false
18+
a; // 1
19+
20+
// normal function:
21+
function f() {} // DontDelete is set
22+
delete f; // false
23+
typeof f; // "function"
24+
25+
// reassigning doesn't help:
26+
f = 1;
27+
delete f; // false
28+
f; // 1
29+
30+
### Explicit properties
31+
32+
There are things which can be deleted normally: these are explicitly set
33+
properties.
34+
35+
// explicitly set property:
36+
var obj = {x: 1};
37+
obj.y = 2;
38+
delete obj.x; // true
39+
delete obj.y; // true
40+
obj.x; // undefined
41+
obj.y; // undefined
42+
43+
In the example above `obj.x` and `obj.y` can be deleted because they have no
44+
`DontDelete` atribute. That's why an example below works too.
45+
46+
// this works fine, except for IE:
47+
var GLOBAL_OBJECT = this;
48+
GLOBAL_OBJECT.a = 1;
49+
a === GLOBAL_OBJECT.a; // true - just a global var
50+
delete GLOBAL_OBJECT.a; // true
51+
GLOBAL_OBJECT.a; // undefined
52+
53+
Here we use a trick to delete `a`. [`this`](#function.this) here refers
54+
to the Global object and we explicitly declare variable `a` as it's property
55+
which allows us to delete it.
56+
57+
IE (at least 6-8) has some bugs, so code above doesn't work.
58+
59+
### Function arguments and built-ins
60+
61+
Functions' normal arguments, [`arguments` object](#function.arguments)
62+
and built-in properties also have `DontDelete` set.
63+
64+
// function arguments and properties:
65+
(function (x) {
66+
67+
delete arguments; // false
68+
typeof arguments; // "object"
69+
70+
delete x; // false
71+
x; // 1
72+
73+
function f(){}
74+
delete f.length; // false
75+
typeof f.length; // "number"
76+
77+
})(1);
78+
79+
### Host objects
80+
81+
Behaviour of `delete` operator can be unpredictable for hosted objects. Due to
82+
specification, host objects are allowed to implement any kind of behavior.
83+
84+
### In conclusion
85+
86+
`delete` operator often has an unexpected behaviour and can be safely used
87+
only for dealing with explicitly set properties on normal objects.

doc/es/core/eval.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## ¿Por qué no usar `eval`?
2+
3+
La función `eval` ejecuta un string como código JavaScript en el ámbito local.
4+
5+
var foo = 1;
6+
function test() {
7+
var foo = 2;
8+
eval('foo = 3');
9+
return foo;
10+
}
11+
test(); // 3
12+
foo; // 1
13+
14+
Pero `eval` sólo ejecutará en ámbito local cuando es llamado **directamente** *y*
15+
el nombre de la función llamada es `eval`.
16+
17+
var foo = 1;
18+
function test() {
19+
var foo = 2;
20+
var bar = eval;
21+
bar('foo = 3');
22+
return foo;
23+
}
24+
test(); // 2
25+
foo; // 3
26+
27+
El uso de `eval` debe evitarse **a toda costa**. El 99.9% de su "uso" puede
28+
lograrse **sin** su uso..
29+
30+
### `eval` disfrazado
31+
32+
Las funciones de [tiempo de espera](#other.timeouts) `setTimeout` y `setInterval` pueden
33+
tomar un string como primer argumento. En este caso, el string **siempre** se ejecutará en
34+
el ámbito global ya que `eval` no ha sido llamado directamente.
35+
36+
### Problemas de seguridad
37+
38+
`eval` es también un problema de seguridad ya que ejecuta **cualquier** código enviado,
39+
y **nunca** debe usarse con strings que no se conozcan o tengan un origen no confiable.
40+
41+
### En conclusión
42+
43+
`eval` nunca debe ser usado, cualquier código que haga uso del mismo debe ser cuestionado
44+
en su funcionamiento, rendimiento y seguridad. En caso de que se necesite trabajar con
45+
`eval`, el diseño ha de ser cuestionado y **no** debe utilizarse en primer lugar, se
46+
debe usar un *mejor diseño*, que no requiera el uso de `eval`.
47+

doc/es/core/semicolon.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
## Automatic Semicolon Insertion
2+
3+
Although JavaScript has C style syntax, it does **not** enforce the use of
4+
semicolons in the source code, so it is possible to omit them.
5+
6+
JavaScript is not a semicolon-less language. In fact, it needs the
7+
semicolons in order to understand the source code. Therefore, the JavaScript
8+
parser **automatically** inserts them whenever it encounters a parse
9+
error due to a missing semicolon.
10+
11+
var foo = function() {
12+
} // parse error, semicolon expected
13+
test()
14+
15+
Insertion happens, and the parser tries again.
16+
17+
var foo = function() {
18+
}; // no error, parser continues
19+
test()
20+
21+
The automatic insertion of semicolon is considered to be one of **biggest**
22+
design flaws in the language because it *can* change the behavior of code.
23+
24+
### How it Works
25+
26+
The code below has no semicolons in it, so it is up to the parser to decide where
27+
to insert them.
28+
29+
(function(window, undefined) {
30+
function test(options) {
31+
log('testing!')
32+
33+
(options.list || []).forEach(function(i) {
34+
35+
})
36+
37+
options.value.test(
38+
'long string to pass here',
39+
'and another long string to pass'
40+
)
41+
42+
return
43+
{
44+
foo: function() {}
45+
}
46+
}
47+
window.test = test
48+
49+
})(window)
50+
51+
(function(window) {
52+
window.someLibrary = {}
53+
54+
})(window)
55+
56+
Below is the result of the parser's "guessing" game.
57+
58+
(function(window, undefined) {
59+
function test(options) {
60+
61+
// Not inserted, lines got merged
62+
log('testing!')(options.list || []).forEach(function(i) {
63+
64+
}); // <- inserted
65+
66+
options.value.test(
67+
'long string to pass here',
68+
'and another long string to pass'
69+
); // <- inserted
70+
71+
return; // <- inserted, breaks the return statement
72+
{ // treated as a block
73+
74+
// a label and a single expression statement
75+
foo: function() {}
76+
}; // <- inserted
77+
}
78+
window.test = test; // <- inserted
79+
80+
// The lines got merged again
81+
})(window)(function(window) {
82+
window.someLibrary = {}; // <- inserted
83+
84+
})(window); //<- inserted
85+
86+
> **Note:** The JavaScript parser does not "correctly" handle return statements
87+
> which are followed by a new line, while this is not neccessarily the fault of
88+
> the automatic semicolon insertion, it can still be an unwanted side-effect.
89+
90+
The parser drastically changed the behavior of the code above. In certain cases,
91+
it does the **wrong thing**.
92+
93+
### Leading Parenthesis
94+
95+
In case of a leading parenthesis, the parser will **not** insert a semicolon.
96+
97+
log('testing!')
98+
(options.list || []).forEach(function(i) {})
99+
100+
This code gets transformed into one line.
101+
102+
log('testing!')(options.list || []).forEach(function(i) {})
103+
104+
Chances are **very** high that `log` does **not** return a function; therefore,
105+
the above will yield a `TypeError` stating that `undefined is not a function`.
106+
107+
### In Conclusion
108+
109+
It is highly recommended to **never** omit semicolons; it is also advocated to
110+
keep braces on the same line with their corresponding statements and to never omit
111+
them for one single-line `if` / `else` statements. Both of these measures will
112+
not only improve the consistency of the code, but they will also prevent the
113+
JavaScript parser from changing its behavior.
114+

0 commit comments

Comments
 (0)