* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
2.1 KiB
2.1 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7dae367417b2b2512b7a | Verify an Object's Constructor with instanceof | 1 | 使用instanceof验证Object的构造函数 |
Description
instance
。 JavaScript提供了一种使用instanceof
运算符验证这一点的便捷方法。 instanceof
允许您将对象与构造函数进行比较,根据是否使用构造函数创建该对象,返回true
或false
。这是一个例子: 让Bird = function(名称,颜色){如果在不使用构造函数的
this.name = name;
this.color = color;
this.numLegs = 2;
}
让乌鸦=新鸟(“亚历克西斯”,“黑色”);
鸟的鸟; // =>是的
instanceof
创建对象, instanceof
将验证它不是该构造函数的实例: 让金丝雀= {
名称:“Mildred”,
颜色:“黄色”,
numLegs:2
};
鸟类的金丝雀; // => false
Instructions
House
构造函数的新实例,将其myHouse
并传递多个卧室。然后,使用instanceof
验证它是House
的实例。 Tests
tests:
- text: <code>myHouse</code>应该将<code>numBedrooms</code>属性设置为数字。
testString: assert(typeof myHouse.numBedrooms === 'number');
- text: 请务必使用<code>instanceof</code>运算符验证<code>myHouse</code>是<code>House</code>的<code>instanceof</code> 。
testString: assert(/myHouse\s*instanceof\s*House/.test(code));
Challenge Seed
/* jshint expr: true */
function House(numBedrooms) {
this.numBedrooms = numBedrooms;
}
// Add your code below this line
Solution
// solution required