I want to trigger a customized job on window resize after certain data is loaded:
function doJob() {
...
}
DataLoaded() {
$(window).on("resize", function() { doJob(); });
}
However DataLoaded
can be occured multiple times, how can I make sure doJob() only bind once ?
PLEASE NOTE, bind once, but can be executed multiple times, so $("...").one("...") is not my goal
IMO:
- set a global variable
isBind
to check if method is bind, which looks redundant- $(window).off("resize").on("resize", ....), I'm not sure if calling off() first is a safe way