@@ -257,92 +257,92 @@ caso su tipo—y deriva propiedades compartidas desde su prototipo.
257257
258258{{id classes}}
259259
260- ## Classes
260+ ## Clases
261261
262262{{index "object-oriented programming"}}
263263
264- JavaScript's ((prototype )) system can be interpreted as a somewhat
265- informal take on an object-oriented concept called _ ((class ))es_ . A
266- class defines the shape of a type of object—what methods and
267- properties it has. Such an object is called an _ ((instance ))_ of the
268- class .
264+ El sistema de ((prototipos )) en JavaScript se puede interpretar como un
265+ enfoque informal de un concepto orientado a objetos llamado _ ((clase ))es_ .
266+ Una clase define la forma de un tipo de objeto—qué métodos y
267+ propiedades tiene este. Tal objeto es llamado una _ ((instancia ))_ de la
268+ clase .
269269
270- Prototypes are useful for defining properties for which all instances
271- of a class share the same value, such as ((method ))s. Properties that
272- differ per instance, such as our rabbits' ` type ` ((property)), need to
273- be stored directly in the objects themselves .
270+ Los prototipos son útiles para definir propiedades en las cuales todas las
271+ instancias de una clase compartan el mismo valor, como ((método ))s.
272+ Las propiedades que difieren por instancia, como la ((propiedad)) ` tipo `
273+ en nuestros conejos, necesitan almacenarse directamente en los objetos mismos .
274274
275275{{id constructors}}
276276
277- So in order to create an instance of a given class, you have to make
278- an object that derives from the proper prototype, but you _ also _ have
279- to make sure it, itself, has the properties that instances of this
280- class are supposed to have. This is what a _ ((constructor)) _ function
281- does .
277+ Entonces, para crear una instancia de una clase dada, debes crear
278+ un objeto que derive del prototipo adecuado, pero _ también _ debes
279+ asegurarte de que, en sí mismo, este objeto tenga las propiedades que
280+ las instancias de esta clase se supone que tengan.
281+ Esto es lo que una función _ ((constructora)) _ hace .
282282
283283```
284- function makeRabbit(type ) {
285- let rabbit = Object.create(protoRabbit );
286- rabbit.type = type ;
287- return rabbit ;
284+ function crearConejo(tipo ) {
285+ let conejo = Object.create(conejoPrototipo );
286+ conejo.tipo = tipo ;
287+ return conejo ;
288288}
289289```
290290
291291{{index "new operator", this, "return keyword", [ object, creation] }}
292292
293- JavaScript provides a way to make defining this type of function
294- easier. If you put the keyword ` new ` in front of a function call, the
295- function is treated as a constructor. This means that an object with
296- the right prototype is automatically created, bound to ` this ` in the
297- function, and returned at the end of the function .
293+ JavaScript proporciona una manera de hacer que la definición de este tipo de
294+ funciones sea más fácil. Si colocas la palabra clave ` new ` ("new") delante de
295+ una llamada de función, la función sera tratada como un constructor. Esto
296+ significa que un objeto con el prototipo adecuado es creado automáticamente,
297+ vinculado a ` this ` en la función, y retornado al final de la función .
298298
299299{{index "prototype property"}}
300300
301- The prototype object used when constructing objects is found by taking
302- the ` prototype ` property of the constructor function .
301+ El objeto prototipo utilizado al construir objetos se encuentra al tomar
302+ la propiedad ` prototype ` de la función constructora .
303303
304304{{index "rabbit example"}}
305305
306306```
307- function Rabbit(type ) {
308- this.type = type ;
307+ function Conejo(tipo ) {
308+ this.tipo = tipo ;
309309}
310- Rabbit .prototype.speak = function(line ) {
311- console.log(`The ${this.type} rabbit says '${line }'`);
310+ Conejo .prototype.hablar = function(linea ) {
311+ console.log(`El conejo ${this.tipo} dice '${linea }'`);
312312};
313313
314- let weirdRabbit = new Rabbit("weird ");
314+ let conejoRaro = new Conejo("raro ");
315315```
316316
317317{{index constructor}}
318318
319- Constructors (all functions, in fact) automatically get a property
320- named ` prototype ` , which by default holds a plain, empty object that
321- derives from ` Object.prototype ` . You can overwrite it with a new
322- object if you want. Or you can add properties to the existing object ,
323- as the example does .
319+ Los constructores (todas las funciones, de hecho) automáticamente obtienen
320+ una propiedad llamada ` prototype ` , que por defecto contiene un objeto simple
321+ y vacío, que deriva de ` Object.prototype ` . Puedes sobrescribirlo con un nuevo
322+ objeto si asi quieres. O puedes agregar propiedades al objeto ya existente ,
323+ como lo hace el ejemplo .
324324
325325{{index capitalization}}
326326
327- By convention, the names of constructors are capitalized so that they
328- can easily be distinguished from other functions .
327+ Por convención, los nombres de los constructores tienen la primera letra en
328+ mayúscula para que se puedan distinguir fácilmente de otras funciones .
329329
330330{{index "prototype property", "getPrototypeOf function"}}
331331
332- It is important to understand the distinction between the way a
333- prototype is associated with a constructor (through its ` prototype `
334- property) and the way objects _ have _ a prototype (which can be found
335- with ` Object.getPrototypeOf ` ). The actual prototype of a constructor
336- is ` Function.prototype ` , since constructors are functions. Its
337- ` prototype ` _ property _ holds the prototype used for instances created
338- through it .
332+ Es importante entender la distinción entre la forma en que un prototipo
333+ está asociado con un constructor (a través de su propiedad ` prototype ` )
334+ y la forma en que los objetos _ tienen _ un prototipo (que se puede
335+ encontrar con ` Object.getPrototypeOf ` ). El prototipo real de un constructor
336+ es ` Function.prototype ` , ya que los constructores son funciones. Su
337+ _ propiedad _ ` prototype ` contiene el prototipo utilizado para las
338+ instancias creadas a traves de el .
339339
340340```
341- console.log(Object.getPrototypeOf(Rabbit ) ==
341+ console.log(Object.getPrototypeOf(Conejo ) ==
342342 Function.prototype);
343343// → true
344- console.log(Object.getPrototypeOf(weirdRabbit ) ==
345- Rabbit .prototype);
344+ console.log(Object.getPrototypeOf(conejoRaro ) ==
345+ Conejo .prototype);
346346// → true
347347```
348348
0 commit comments