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 6981155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:07:11+00:00 2026-05-27T18:07:11+00:00

I am currently developing a rather complex jQuery plugin. One that I am designing

  • 0

I am currently developing a rather complex jQuery plugin. One that I am designing to be extensible. The quandary I have is how to exactly provide my users with the APIs available to them.

There are two methods that I can come up with:

  1. Provide the API via an object in the global scope

    This is the method I am currently using. I do it similar to this:

    (function ($, win, undefined) {
        //main plugin functionality
        function pluginStuff() { /*...including method calling logic...*/ }
    
        //register function with jQuery
        $.fn.extend({ Plugin: pluginStuff });
    
        //register global API variable
        win.PluginAPI = { extendMe: {}, getVar: function() {} };
    })(jQuery, window);
    

    Unfortunately since I impliment the standard $().plugin('method') architecture its a little strange to have to use the jQuery method for some things and the API variable for others.

  2. Provide the API via an object placed in jQuery

    I toyed with this method as well but its best practice to take up only a single slot in jQueries fn scope, as not to crowd the jQuery variable. In this method I would put my api variable in $.fn instead of the window:

    //register function with jQuery
    $.fn.extend({ Plugin: pluginStuff });
    
    //register global API variable
    $.fn.PluginAPI = { extendMe: {}, getVar: function() {} };
    

    I would rather not break this convention and take up two places.


Now that I write this I can see a third option where I assign my plugins slot in jQuery’s fn scope to be an object:

$.fn.Plugin = { plugin: pluginStuff, api: { extendMe: {}, getVar: function() {} } };

but how well received would this be if users had to do $('#elm').Plugin.plugin({ setting: 'value' }) to create a new instance of the plugin?

Any help or pointers would be greatly appreciated.

Please Note: I’m am not looking for a way to incorporate the API object into my plugin functionality. I am looking for a way to keep it separately modularized, but intuitively available for use/extension.

  • 1 1 Answer
  • 0 Views
  • 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-27T18:07:12+00:00Added an answer on May 27, 2026 at 6:07 pm

    The method I eventually decided to use was registering the plugin under the fn namespace and the api variable under the jQuery $ namespace. Since methods and options set operate on an instance of the plugin $.fn is the best choice.

    However, the API is global and does not link to a single instance. In this case $.fn doesn’t quite fit. What I ended up using was something similar to this:

    (function ($, win, undefined) {
        //main plugin functionality
        function pluginStuff() { /*...including method calling logic...*/ }
    
        //register function with jQuery
        $.fn.Plugin = pluginStuff;
    
        //register global API variable
        $.Plugin = { extendMe: {}, getVar: function() {} };
    })(jQuery, window);
    

    now you can create an use a plugin object as expected:

    $('#elm').Plugin();
    $('#elm').Plugin('option', 'something', 'value');
    $('#elm').Plugin('method');
    

    and you can easily extend and access the API:

    $.extend($.Plugin.extendMe, {
        moreStuff: {}
    });
    $.Plugin.getVar('var');
    

    Thanks for the help everyone!

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

Sidebar

Related Questions

We're currently developing a Windows Smartclient that needs to authenticate users using their AD
I am developing a SQL query that currently works for one group/mode combination. But
I am developing a complex form that updates several records of one model at
I am currently developing jquery code that sends data to the server via ajax
I have an Android app that I am currently developing. I have created icons
Currently developing a PHP framework and have ran into my first problem. I need
I am currently developing an approval routing WCF service that will allow an user
I am currently developing a Rails application using a database that was designed before
I'm currently developing a PHP application that's using an Access database as a backend.
I'm currently developing an application that is comprised of five separate executables that communicate

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.