Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3395322
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:16:34+00:00 2026-05-18T04:16:34+00:00

lately I have been writing a lot of tiny plugins for my web projects

  • 0

lately I have been writing a lot of tiny plugins for my web projects but I am still very much a beginner in plugin authoring.

I have been doing a lot of reading on jquery plugins but I simply cannot wrap my head around methods.

Here is what my current plugins mostly look like:

(function($){

    $.fn.extend({ 

        myHelper: function(options) {

            var defaults = {
                some: 'defaults'
            }

            var options =  $.extend(defaults, options);

            return this.each(function() {
                var o = options;

                function next(target) {
                    // do something like slide to the next image in a slideshow 
                    // based on the target and count passed in
                    slide('right');
                }
                function prev(target) {
                    slide('left');
                }

                function slide(direction) {
                    // animation for sliding in the next one
                    $('ul > li.current').animate({ … }, 800);
                }

                // doesn't exactly make sense but its just to illustrate what I need to do.
                $('.next').click(next($('ul > #example'));


            });
        }
    });

})(jQuery);

What I am after now, and I thought method was the way to go here… is to basically not have all these named functions for tiny bits of functionality and instead define methods such as nextSlide, prevSlide, reset, loop i think you get the idea…

You may have noticed that I pass things such as the target into the function (next() for example) and then call the next() as a standalone thing.

I now want to start doing this by simply having a method do all this and enable me to write within my plugin.js file something like $(o.nextBtn).nextSlide(); for example.

But how do I write a method that accepts arguments such as the target in this example?

All the examples and tutorials for methods I have found so far basically didn’t have an option of accepting arguments into the method’s function. Is this even possible?

Ideally I’d like to make these functions chainable within the my plugin as well but this is starting to get way over my head.

If you know how to create something that does what I want to accomplish in a neat and organized manner or have a good tutorial I should look at, please share.

Thanks.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:16:34+00:00Added an answer on May 18, 2026 at 4:16 am

    The recommended way to build a jQuery plugin is to actually place all of your methods into an array, and then use the plugin’s main function to access them.

    For example, using some of your example:

    function($) {
        var methods = {
          next(target) {
              target.foo();
          }
     };
    
     $.fn.plugin = function( method ) {
    
        if ( methods[method] ) {
          return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
          return methods.init.apply( this, arguments );
        } else {
          $.error( 'Method ' +  method + ' does not exist on jQuery.tooltip' );
        }    
    
      };
    
    })( jQuery );
    
    To use it then:
    var blah = $('#' + elemID).plugin('init');
    blah.plugin('next','#'+ some_other_element);
    

    In this example, the blah is the object representing your plugin, and then you use the plugin’s method to call functions and pass in the values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been writing code like the following enough a lot lately. I don't
Lately I have been reading a lot of blog topics about big sites(facebook, twitter,
I have lately been developing a very simple app for iOS with PhoneGap. All
I have been reading a lot of Javascript lately and I have been noticing
I am a university student. I have been working a lot with Android lately
So lately I have been working on writing a simple compiler to better understand
I've been writing some migrations lately which fall under the Irreversible Migration umbrella. But
Lately, I've been writing a lot of code that looks like this: List<MyObject> myList
I've been doing a lot of work with Flex/Flash/Away3D lately, and have started looking
Lately I have been reading about web crawling, indexing and serving. I have found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.