回调函数不使用方法

时间:2017-08-23 11:46:05

标签: javascript

我只是学习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);

此代码显示此错误: enter image description here

0 个答案:

没有答案