直接将数组作为参数传递时,数组对象属性为空

时间:2018-10-06 13:30:21

标签: javascript arrays arguments javascript-objects

我有这个对象:

function Student(name, grades) {
    this.name = name;
    this.grades = grades;

    this.getName = () => this.name;
    this.getGrades = () => this.grades;
}

grades应该是一个数组。但是当我这样做时:

let student = new Student('James', [1, 2, 3])
console.log(student.getGrades)

数组grades为空。我究竟做错了什么?直接将数组作为参数传递会出问题吗?

谢谢!


0 个答案:

没有答案