While developing a jQuery plugin I thought about how cool it would be if it had a callback capability, but I wasn’t sure if I wanted to write tons of lines of code for a feature that wasn’t essential.
Then I did some research and realized it would only takes two lines of code to make this happen.
Assuming you’re using good practices to create your default values:
Then later in the program, let’s say for example you need the callback to trigger when a close button is clicked:
And here’s an example of how it would be used:
And that’s it. Super simple and now your plugin users can easily add functionality.