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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:16:20+00:00 2026-06-05T09:16:20+00:00

I have created a plugin with following codes: var myplugin = { init: function(options)

  • 0

I have created a plugin with following codes:

var myplugin = {
    init: function(options) {
         $.myplugin.settings = $.extend({}, $.myplugin.defaults, options);
    },
    method1: function(par1) {
        .....
    },
    method2: function(par1) {
        .....
    }
};
$.myplugin = function(method){
     if ( myplugin[method] ) {
    return myplugin[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
     } else if (typeof method === 'object' || !method) {
        return myplugin.init.apply(this, arguments);
     } else {
    $.error( 'Method "' +  method + '" does not exist in myplugin!');
     }
};
$.myplugin.defaults = {
     option1: 'test',
     option2: '',
     option3: ''
};
$.myplugin.settings = {};
$.myplugin();

This works well but the issue is that when I try to set more than 1 option and try to return its values afterwards, it gives empty; setting one option works well. For eg.
If on changing the first combo box value I call this:
$.myplugin({option1: ‘first test’});
it works, but when I try to call another on second combo box it doesn’t save the option, instead it reset to empty.

Is there any fix?

  • 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-06-05T09:16:21+00:00Added an answer on June 5, 2026 at 9:16 am

    I would re-organize the plugin to use this structure:

    var methods = {
        settings: {
            foo: "foo",
            bar: "bar"
        },
        init: function(options) {
            this.settings = $.extend({}, this.settings, options);
        },
        method1: function(par1) {
            alert(this.settings.foo);
        },
        method2: function(par1) {
            alert(this.settings.bar);
        }
    };
    
    function MyPlugin(options) {
        this.init(options);
        return this;
    }
    $.extend(MyPlugin.prototype, methods);
    $.myPlugin = function(options) {
        return new MyPlugin(options);
    }
    
    /* usage */
    
    // without parameters
    var obj1 = $.myPlugin();
    // with parameters
    var obj2 = $.myPlugin({foo: "foobar"});
    // each has it's own settings
    obj1.method1();
    obj2.method1();
    

    Demo: http://jsfiddle.net/ypXdS/

    Essentially $.myPlugin simply creates and returns a new instance of the MyPlugin class. You could get rid of it completely and use new myPlugin(options) in it’s place.

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

Sidebar

Related Questions

I have the following code (function($) { // carousel var Carousel = { settings:
I created a jQuery plugin but I have a problem, I use the following
I have created an Eclipse plugin which creates a view in Eclipse. Currently it
I have created a jquery plugin to expand/collapse ul,li something like a accordion menu
I have created a simple WordPress plugin that automatically sets my new sites up
I have created a model test case in a plugin. Plugin name: Filters and
I am using the jQuery Tools Scrollable plugin - http://flowplayer.org/tools/scrollable.html#navigator I have created a
I created a jQuery plugin to modify my navigation. Unfortunately I have to access
I am using the jquery-ui-map plugin (http://code.google.com/p/jquery-ui-map/). I have successfully created a map using
I just created a javscript plugin that waits for all the images. The following

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.