<sectionid="description"> Aquí está el constructor de <code>Bird</code> del desafío anterior: <blockquote> función Bird () { <br> this.name = "Albert"; <br> this.color = "blue"; <br> this.numLegs = 2; <br> // "esto" dentro del constructor siempre se refiere al objeto que se está creando <br> } <br><br> Deje que blueBird = new Bird (); </blockquote> Observe que el <code>new</code> operador se utiliza al llamar a un constructor. Esto le dice a JavaScript que cree una nueva <code>instance</code> de <code>Bird</code> llamada <code>blueBird</code> . Sin el <code>new</code> operador, <code>this</code> dentro del constructor no apuntaría al objeto recién creado, dando resultados inesperados. Ahora <code>blueBird</code> tiene todas las propiedades definidas dentro del constructor de <code>Bird</code> : <blockquote> blueBird.name; // => Albert <br> blueBird.color; // => azul <br> blueBird.numLegs; // => 2 </blockquote> Al igual que cualquier otro objeto, se puede acceder y modificar sus propiedades: <blockquote> blueBird.name = 'Elvira'; <br> blueBird.name; // => Elvira </blockquote></section>
<sectionid="instructions"> Usa el constructor <code>Dog</code> de la última lección para crear una nueva instancia de <code>Dog</code> , asignándola a un <code>hound</code> variable. </section>
- text: <code>hound</code> debe ser creado usando el constructor de <code>Dog</code> .
testString: 'assert(hound instanceof Dog, "<code>hound</code> should be created using the <code>Dog</code> constructor.");'
- text: Tu código debe usar el <code>new</code> operador para crear una <code>instance</code> de <code>Dog</code> .
testString: 'assert(code.match(/new/g), "Your code should use the <code>new</code> operator to create an <code>instance</code> of <code>Dog</code>.");'