How it works…
In step 1, we added an Immediately-Invoked Function Expression (IIFE). This is what every plugin should start with. The only parameter passed into the function declaration is the $, and the argument passed to the function call is jQuery. Doing this solves several problems, such as using the IIFE will make our code self-contained. Passing it the $ as the parameter will ensure that this $ is indeed referring to jQuery and not some other library that might also potentially use the $ and clash with our code. That's why we invoke the IIFE by passing jQuery as its argument.
In step 2, we attach our plugin, called canYouFindIt, onto jQuery.fn (or $.fn for short). This is crucial to make the plugin work. Without going into too much ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access