--- id: 587d7daf367417b2b2512b7e title: Understand the Constructor Property challengeType: 1 forumTopicId: 301327 localeTitle: Понять свойство конструктора --- ## Description
Существует специальное свойство constructor расположенное на объектных экземплярах duck и beagle которые были созданы в предыдущих задачах:
let duck = new Bird ();
let beagle = new Dog ();

console.log (duck.constructor === Bird); // выводит true
console.log (beagle.constructor === Собака); // выводит true
Обратите внимание, что свойство constructor является ссылкой на конструктор, создавший экземпляр. Преимущество свойства constructor заключается в том, что можно проверить это свойство, чтобы узнать, какой он объект. Вот пример того, как это можно использовать:
function joinBirdFraternity (кандидат) {
if (кандидат.конструктор === Птица) {
return true;
} else {
return false;
}
}
Заметка
Поскольку свойство constructor может быть перезаписано (что будет рассмотрено в следующих двух задачах), лучше всего использовать метод instanceof для проверки типа объекта.
## Instructions
Write a joinDogFraternity function that takes a candidate parameter and, using the constructor property, return true if the candidate is a Dog, otherwise return false.
## Tests
```yml tests: - text: joinDogFraternity should be defined as a function. testString: assert(typeof(joinDogFraternity) === 'function'); - text: joinDogFraternity should return true ifcandidate is an instance of Dog. testString: assert(joinDogFraternity(new Dog("")) === true); - text: joinDogFraternity should use the constructor property. testString: assert(/\.constructor/.test(code) && !/instanceof/.test(code)); ```
## Challenge Seed
```js function Dog(name) { this.name = name; } // Add your code below this line function joinDogFraternity(candidate) { } ```
## Solution
```js function Dog(name) { this.name = name; } function joinDogFraternity(candidate) { return candidate.constructor === Dog; } ```