获取方法(对象)之外的变量

时间:2018-02-13 11:00:48

标签: javascript oop variables methods

我希望在方法之外检索变量,但OOP对我来说是新的,我有点卡住...

const Reservation = {
    play: document.getElementById('Reservation'),
    reset: document.getElementById('annuler'),

    launch_functions_sessionStorage: function () {
        this.onReservation();
        this.displayIfChecked();
        this.set_Timer();
    },

    displayIfChecked: function () {
        SOMETHING
    },

    onReservation: function () {
        $('#Reservation, .signature',).click(function () {
            console.log();
            if (SOMETHING) {
                let checked = 1;
            } else {
                let checked = 0;
            }
        });
    },

    set_Timer: function () {

        Reservation.play.addEventListener('click', function(){
            if('I would like to get 'checked'){}
        });
    }
};
Reservation.launch_functions_sessionStorage();

我试图保留重要信息以便您理解。 同时抱歉我的英语...... 非常感谢你

1 个答案:

答案 0 :(得分:2)

这是你在找什么?

for

你会像

一样使用它
const Reservation = {
    play: document.getElementById('Reservation'),
    reset: document.getElementById('annuler'),

    launch_functions_sessionStorage: function () {
        this.onReservation();
        this.displayIfChecked();
        this.set_Timer();
    },

    displayIfChecked: function () {
        SOMETHING
    },

    onReservation: function () {
        $('#Reservation, .signature',).click(function () {
            console.log();
            if (SOMETHING) {
                let checked = 1;
            } else {
                let checked = 0;
            }
        });
    },
    varThatCanBeCheckedInSetTimer : false,
    set_Timer: function () {
        Reservation.play.addEventListener('click', function(){
            if(varThatCanBeCheckedInSetTimer){
                //your stuff that will happen only if you set varThatCanBeCheckedInSetTimer  to true
             }
        });
    }
};