<sectionid="description"> Hay un principio en la programación llamado <code>Don't Repeat Yourself (DRY)</code> . La razón por la cual el código repetido es un problema es porque cualquier cambio requiere un código de corrección en varios lugares. Esto generalmente significa más trabajo para los programadores y más espacio para errores. Observe en el siguiente ejemplo que <code>Bird</code> y <code>Dog</code> comparten el método de <code>describe</code> : <blockquote> Bird.prototype = { <br> constructor: pájaro, <br> describe: function () { <br> console.log ("Mi nombre es" + this.name); <br> } <br> }; <br><br> Dog.prototype = { <br> constructor: perro, <br> describe: function () { <br> console.log ("Mi nombre es" + this.name); <br> } <br> }; </blockquote> El método <code>describe</code> se repite en dos lugares. El código se puede editar para seguir el principio <code>DRY</code> creando un <code>supertype</code> (o padre) llamado <code>Animal</code> : <blockquote> función Animal () {}; <br><br> Animal.prototype = { <br> constructor: animal, <br> describe: function () { <br> console.log ("Mi nombre es" + this.name); <br> } <br> }; </blockquote> Ya que <code>Animal</code> incluye el método de <code>describe</code> , puedes eliminarlo de <code>Bird</code> and <code>Dog</code> : <blockquote> Bird.prototype = { <br> constructor: pájaro <br> }; <br><br> Dog.prototype = { <br> constructor: perro <br> }; </blockquote></section>
<sectionid="instructions"> El método de <code>eat</code> se repite tanto en el <code>Cat</code> como en el <code>Bear</code> . Edite el código en el espíritu de <code>DRY</code> moviendo el método de <code>eat</code> al <code>supertype</code><code>Animal</code> . </section>