Files
.github
api-server
client
config
curriculum
challenges
_meta
arabic
chinese
english
portuguese
russian
spanish
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
debugging
es6
functional-programming
intermediate-algorithm-scripting
javascript-algorithms-and-data-structures-projects
object-oriented-programming
add-methods-after-inheritance.spanish.md
change-the-prototype-to-a-new-object.spanish.md
create-a-basic-javascript-object.spanish.md
create-a-method-on-an-object.spanish.md
define-a-constructor-function.spanish.md
extend-constructors-to-receive-arguments.spanish.md
inherit-behaviors-from-a-supertype.spanish.md
iterate-over-all-properties.spanish.md
make-code-more-reusable-with-the-this-keyword.spanish.md
override-inherited-methods.spanish.md
remember-to-set-the-constructor-property-when-changing-the-prototype.spanish.md
reset-an-inherited-constructor-property.spanish.md
set-the-childs-prototype-to-an-instance-of-the-parent.spanish.md
understand-own-properties.spanish.md
understand-the-constructor-property.spanish.md
understand-the-immediately-invoked-function-expression-iife.spanish.md
understand-the-prototype-chain.spanish.md
understand-where-an-objects-prototype-comes-from.spanish.md
use-a-constructor-to-create-objects.spanish.md
use-a-mixin-to-add-common-behavior-between-unrelated-objects.spanish.md
use-an-iife-to-create-a-module.spanish.md
use-closure-to-protect-properties-within-an-object-from-being-modified-externally.spanish.md
use-dot-notation-to-access-the-properties-of-an-object.spanish.md
use-inheritance-so-you-dont-repeat-yourself.spanish.md
use-prototype-properties-to-reduce-duplicate-code.spanish.md
verify-an-objects-constructor-with-instanceof.spanish.md
regular-expressions
03-front-end-libraries
04-data-visualization
06-information-security-and-quality-assurance
08-coding-interview-prep
09-certificates
adddir.js
translatemd.js
formattingConversion
math-challenges
requiresTests
schema
.babelrc
.editorconfig
.eslintignore
.eslintrc
.npmignore
.prettierrc
.travis.yml
CHANGELOG.md
LICENSE.md
addAssertsToTapTest.js
challengeTitles.js
commitizen.config.js
commitlint.config.js
create-challenge-bundle.js
getChallenges.js
gulpfile.js
index.js
lib.js
md-translation.js
mongoIds.js
package-entry.js
package-lock.json
package.json
repack.js
test-challenges.js
unpack.js
unpacked.css
unpacked.js
unpackedChallenge.js
utils.js
docs
news
tools
.editorconfig
.eslintignore
.eslintrc
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README.md
docker-compose-shared.yml
docker-compose.yml
lerna.json
netlify.toml
package-lock.json
package.json
sample.env
freeCodeCamp/curriculum/challenges/spanish/02-javascript-algorithms-and-data-structures/object-oriented-programming/verify-an-objects-constructor-with-instanceof.spanish.md

58 lines
2.4 KiB
Markdown
Raw Normal View History

2018-10-08 13:34:43 -04:00
---
id: 587d7dae367417b2b2512b7a
title: Verify an Object's Constructor with instanceof
challengeType: 1
2018-10-10 16:20:40 -04:00
videoUrl: ''
localeTitle: Verifique el constructor de un objeto con instanceof
2018-10-08 13:34:43 -04:00
---
## Description
2018-10-10 16:20:40 -04:00
<section id="description"> Cada vez que una función constructora crea un nuevo objeto, se dice que ese objeto es una <code>instance</code> de su constructor. JavaScript ofrece una forma conveniente de verificar esto con el operador <code>instanceof</code> . <code>instanceof</code> permite comparar un objeto con un constructor, devolviendo <code>true</code> o <code>false</code> según si ese objeto fue creado con el constructor o no. Aquí hay un ejemplo: <blockquote> deja a Bird = función (nombre, color) { <br> this.name = nombre; <br> this.color = color; <br> this.numLegs = 2; <br> } <br><br> dejar cuervo = nuevo pájaro (&quot;Alexis&quot;, &quot;negro&quot;); <br><br> Cuervo de pájaro; // =&gt; verdadero </blockquote> Si se crea un objeto sin usar un constructor, <code>instanceof</code> verificará que no es una instancia de ese constructor: <blockquote> dejar canario = { <br> nombre: &quot;Mildred&quot;, <br> color amarillo&quot;, <br> NumLegs: 2 <br> }; <br><br> ejemplar canario de ave; // =&gt; falso </blockquote></section>
2018-10-08 13:34:43 -04:00
## Instructions
2018-10-10 16:20:40 -04:00
<section id="instructions"> Cree una nueva instancia del constructor de <code>House</code> , llamándola <code>myHouse</code> y pasando varias habitaciones. Luego, use <code>instanceof</code> para verificar que es una instancia de <code>House</code> . </section>
2018-10-08 13:34:43 -04:00
## Tests
<section id='tests'>
```yml
tests:
- text: <code>myHouse</code> debería tener un atributo <code>numBedrooms</code> establecido en un número.
testString: 'assert(typeof myHouse.numBedrooms === "number", "<code>myHouse</code> should have a <code>numBedrooms</code> attribute set to a number.");'
- text: Asegúrese de verificar que <code>myHouse</code> es una instancia de <code>House</code> usa el operador <code>instanceof</code> .
testString: 'assert(/myHouse\s*instanceof\s*House/.test(code), "Be sure to verify that <code>myHouse</code> is an instance of <code>House</code> using the <code>instanceof</code> operator.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
/* jshint expr: true */
function House(numBedrooms) {
this.numBedrooms = numBedrooms;
}
// Add your code below this line
```
</div>
</section>
## Solution
<section id='solution'>
```js
2018-10-10 16:20:40 -04:00
// solution required
2018-10-08 13:34:43 -04:00
```
</section>