Reputation: 455
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
Upvotes: 2
Views: 160
Reputation: 413682
When you instantiate a function using the syntax typically employed for self-invoking functions, you're creating an anonymous function even though you give it a name. In a function instantiation expression, the name you give after the function
keyword is bound inside the function, and not outside.
(That's actually not true in Internet Explorer, but that's because Internet Explorer is broken.)
Upvotes: 1
Reputation: 359776
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();
});
Upvotes: 3