Can I use callback with self-executing function?
If yes, have you seen any examples?
JavaScript self-executing function:
(function(){
//Do Stuff
})()
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Of course you can – this is common way of enclosing your variables within some function so they do not interfere with global variables (or from separate closures).
Some example:
Thanks to the closures, the variables from them are not interfering with the ones from different closure (different anonymous function).
Working example in this jsfiddle.
EDIT:
Is you want to execute the code from some callback in such function, you may write something like that:
or even like that:
which, however, seems to be rather careless and unnecessarily increasing the complexity of your code.