freecodecamp.cn
freecodecamp.cn copied to clipboard
关卡Make Unique Objects by Passing Parameters to our Constructor :bug
chrome win7
已经仿照 例子,并修改了相关数据,仍然不通过
你的代码
var Car = function() {
//Change this constructor
this.wheels = 4;
this.seats = 1;
this.engines = 1;
};
//Try it out here
var myCar;
myCar = new Car(3,1,2);
var myCar1 = new Car(4,4, 2);
var myCar2 = new Car(2, 6, 3);
截图(如果有)
此题的目的是让你理解 this, 答案是 类似this.wheels = wheels;这样的。题并没有bug,请不要再来issue提问。
通过构造函数将一个参数作为特定的 this 关键字的值传递给新创建的空对象。 然后构造函数负责为新对象执行适应的初始化(创建属性并给出其初始值)。完成后,构造函数返回它所构造的对象的一个参数。
@yayayhoo
改动 Car 的构造函数 ,使它能够通过使用参数来为 wheels 、 seats 、 engines 属性进行赋值。
例子:var Car = function(wheels, seats, engines)
构造函数的参数你也没加。请仔细看题