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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:03:23+00:00 2026-06-01T07:03:23+00:00

Following the good jQuery Plugins/Authoring instructions I have a little question (function($){ // Default

  • 0

Following the good jQuery Plugins/Authoring instructions I have a little question

(function($){

  // Default Settings
  var settings = {
    var1: 50
  , var2: 100
  };

  var methods = {
    init : function (options) {
      console.log(settings);
      settings = $.extend(options, settings); // Overwrite settings
      console.log(settings);
      return this;
    }
  , other_func: function () {
      return this;
    }
  };

  $.fn.my_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.my_plugin');
    }    
  };

})(jQuery);

If I do

>>> $('my_element').my_plugin({var3: 60})
Before Object { var2=100, var1=50}
After Object { var3=60, var2=100, var1=50}
[ my_element ]

>>> $('my_element').my_plugin({var1: 60})
Before Object { var1=50, var2=100}
After Object { var1=50, var2=100}
[ my_element ]

Why is my var1 not overridden ?

  • 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-01T07:03:25+00:00Added an answer on June 1, 2026 at 7:03 am

    You mixed up the order of the arguments in your $.extend (target should be first), it should be:

    settings = $.extend(settings, options);
    

    See this fiddle and the docs for $.extend()

    To avoid confusion you can also extend your settings with your defaults like this:

    methods.init = function(options){
    
      var settings = $.extend({
        key1: 'default value for key 1',
        key2: 'default value for key 2'
      }, options); // <- if no / undefined options are passed extend will simply return the defaults
    
      //here goes the rest
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following jQuery code $('a.editpo, a.resetpass').click(function(event){ event.preventDefault(); var urlToCall = $(this).attr('href'); var hyperlinkid
After asking the following questions: Question 1: Are there any good JQuery twitter widgets
I have the following javascript : var MyObject = (function() { function Setup(args) {
I have the following in my (document).ready function: replace_fav_url(); and the jQuery function: function
Consider the following jQuery implementation defined using an object literal... $(function() { var myObject
Following this question: Good crash reporting library in c# Is there any library like
Good Day. I'm looking for switch replacement in jQuery. Basically, I have no idea
I have the following jQuery statement: $.ajax({ type: POST, url: db.php, data: word=+ tmpWord,
I have a mobile web application built using the following versions :- JQuery Mobile
I am looking for a good jquery plugin for form validation. 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.