May 2017
Intermediate to advanced
448 pages
10h 10m
English
We have seen many examples in the jQuery API of options objects being provided as parameters of methods such as .animate() and $.ajax(). This can be a much friendlier way to expose options to a plugin user than the simple parameter list we just used with the .swapClass() plugin. An object literal provides a visual label for each parameter and also makes the order of the parameters irrelevant. In addition, any time we can mimic the jQuery API in our plugins, we should do so. This will increase the consistency and therefore ease of use:
(($) => { $.fn.shadow = function(options) { return this.each((i, element) => { const $originalElement = $(element); for (let i = 0; i < options.copies; i++) { $originalElement .clone() .css({ ...Read now
Unlock full access