我想通过这个简单的测试赋值和我有麻烦搞清楚如何适合它的构造函数,如何使一个在Javascript中使用函数的对象构造函数?
describe("Student", function(){
var student;
beforeEach(function(){
student = new Student({firstName: "Lysette", scores: [100, 100, 100, 4, 100]});
});
describe("name", function() {
it("has a first name", function() {
expect(student.firstName).toEqual("Lysette");
});
});
我已经试过这一点,但它似乎没有要工作:
var Student = function (firstName, scores){
this.firstName = firstName;
this.scores = scores;
};
任何解决方案?
什么哟由意味着“似乎并不奏效”? –
您正在传递包含两个属性“firstName”和“scores”的对象,而不是两个单独的参数。你想要哪些行为? –
这与构造函数的功能有什么关系? – Bergi