I would like to immediately execute an event after I bind it. For example:
$(window).resize(function () {
alert("Some code");
});
Typically what I've done in the past is:
$(function() {
$(window).resize(resizeFunc);
resizeFunc(); //This will execute immediately
});
function resizeFunc() {
alert("Some code");
}
But that is not helpful for anonymous functions, and it is a bit verbose. I'd like to do something like: $(window).resize(function () {})();
or $(window).resize(function () {}).trigger();
but those don't work.
Is there a way to immediately execute anonymous functions on bind?