--- id: 587d7dad367417b2b2512b77 title: Define a Constructor Function challengeType: 1 videoUrl: '' localeTitle: 定义构造函数 --- ## Description
Constructors函数是创建新对象的函数。它们定义属于新对象的属性和行为。将它们视为创建新对象的蓝图。以下是constructor的示例:
function Bird(){
this.name =“阿尔伯特”;
this.color =“blue”;
this.numLegs = 2;
}
constructor定义一个Bird对象,其属性namecolornumLegs设置为Albert,blue和2。 Constructors遵循一些约定:
## Instructions
创建一个constructor Dog ,其属性namecolornumLegs分别设置为字符串,字符串和数字。
## Tests
```yml tests: - text: Dog应该将name属性设置为字符串。 testString: 'assert(typeof (new Dog()).name === "string", "Dog should have a name property set to a string.");' - text: Dog应该将color属性设置为字符串。 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
```js ```
## Solution
```js // solution required ```