---
id: 587d7dad367417b2b2512b77
title: Define a Constructor Function
challengeType: 1
videoUrl: ''
localeTitle: Определение функции конструктора
---
## Description
Constructors
- это функции, которые создают новые объекты. Они определяют свойства и поведение, которые будут принадлежать новому объекту. Подумайте о них как о плане создания новых объектов. Вот пример constructor
: функция Bird () {
this.name = "Альберт";
this.color = "blue";
this.numLegs = 2;
}
Этот constructor
определяет объект Bird
с name
свойств, color
и numLegs
установленными на Albert, blue и 2, соответственно. Constructors
следуют нескольким соглашениям: -
Constructors
определяются с заглавным именем, чтобы отличать их от других функций, которые не являются constructors
. -
Constructors
используют ключевое слово this
для установки свойств объекта, который они создадут. Внутри constructor
this
относится к новому объекту, который он создаст. -
Constructors
определяют свойства и поведение вместо того, чтобы возвращать значение, как могли бы другие функции.
## Instructions
undefined
## Tests
```yml
tests:
- text: Dog
должно быть свойство name
заданное в строке.
testString: 'assert(typeof (new Dog()).name === "string", "Dog
should have a name
property set to a string.");'
- text: ''
testString: 'assert(typeof (new Dog()).color === "string", "Dog
should have a color
property set to a string.");'
- text: Dog
должно быть свойство numLegs
заданное числом.
testString: 'assert(typeof (new Dog()).numLegs === "number", "Dog
should have a numLegs
property set to a number.");'
```
## Challenge Seed
## Solution
```js
// solution required
```