Creating additional plugin methods

We are almost finishing our plugin. Now, it's time to add some methods to be called in the plugin, just like you can call .carousel('pause') on Bootstrap Carousel for instance.

When we were creating the plugin base, we created a class Plugin, which is the definition of the plugin. This part of the code is pretty common across the plugins and it is used on every native Bootstrap plugin:

function Plugin(option) { var args = arguments; [].shift.apply(args); return this.each(function () { var $this = $(this), data = $this.data('bootstrap-carousel'), options = $.extend({}, BootstrapCarousel.DEFAULTS, $this.data(), typeof option == 'object' && option), value; if (!data) { $this.data('bootstrap-carousel', (data = new ...

Get Bootstrap 4 – Responsive Web Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.