我只是学习JS回调函数,在这段代码中,当我单独运行seniorOrJunior方法时,它工作得很好但是当我通过回调函数调用它时它显示以下错误!
let date = new Date();
let john = {
id : 0123,
name : 'Not Set',
joinYear : 2015,
category : 'Not Set',
position : 'Software Engineer',
fullname : function (firstname, lastname) {
this.name = 'firstname' + ' ' + 'lastname';
},
checkLength : function() {
date.getFullYear() - this.joinYear;
},
seniorOrJunior : function () {
if (this.checkLength() < 2) {
this.category = 'Junior';
} else {
this.category = 'Senior';
}
}
}
function salary(callback) {
callback();
if (john.category === seniorOrJunior) {
console.log('Your salary is 40k');
} else if (john.category === seniorOrJunior) {
console.log('Your Salary is 25k');
}
}
salary(john.seniorOrJunior);