我有这个对象:
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
为空。我究竟做错了什么?直接将数组作为参数传递会出问题吗?
谢谢!