Home Get variables outside of method (object)
Reply: 1

Get variables outside of method (object)

Ludovic WEBER
1#
Ludovic WEBER Published in 2018-02-13 11:00:48Z

I am looking to retrieve variables outside a method, but OOP is something new for me, i'm a little stuck ...

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();

I tried to keep important information for your understanding. Meanwhile sorry for my english... Thank you very much

Leja Vaitkeviciute
2#
Leja Vaitkeviciute Reply to 2018-02-13 11:25:08Z

Is this what you are looking 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
             }
        });
    }
};

you would use it like

Reservation.varThatCanBeCheckedInSetTimer = true;
Reservation.set_Timer();
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299919 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO