Gabotronix
4 months ago
101
3
General

Javascript: adding a single function to multiple events

Posted 4 months ago by Gabotronix

Hi everybody, currently I have something like this:

window.addEventListener('load', function() {
        self.checkIsMobile();
    });

    window.addEventListener('resize', function() {
        self.checkIsMobile();
    }); 

Is it possible to do the same action for multiple events in a single line, something like:

window.addEventListener(['load', 'resize'], function() {
        self.checkIsMobile();
});

Thnaks in advance

Please sign in or create an account to participate in this conversation.