May 2017
Intermediate to advanced
448 pages
10h 10m
English
Of course, some method parameters can be more complicated than a simple numeric value. One common parameter type we have seen frequently throughout the jQuery API is the callback function. The callback function can lend flexibility to a plugin without requiring a great deal of preparation when creating the plugin.
To use a callback function in our method, we need to simply accept the function object as a parameter and call that function wherever appropriate in our method implementation. As an example, we can extend our text shadow method to allow the user to customize the position of the shadow relative to the text:
(($) => { $.fn.shadow = function(opts) { const defaults = { copies: 5, opacity: 0.1, copyOffset: index => ...Read now
Unlock full access