javascriptiifeself-invoking-function

How can I invoke a named IIFE again by the name I gave it?


Im trying to call to self-invoking function this way:

(function fullscreen(){
  alert("test");
})();
$(window).resize(function() {
  fullscreen();
});

it works only once. no response on window.resize thanks


Solution

  • What you're doing does not make sense. Why is fullscreen self-invoking? Just do this:

    function fullscreen() {
      alert("test");
    }
    
    fullscreen();
    
    $(window).resize(fullscreen);
    // or
    $(window).resize(function () {
        fullscreen();
    });