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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:22:29+00:00 2026-06-16T01:22:29+00:00

I have code that looks like: (function($, window, undefined){ var options, methods = {

  • 0

I have code that looks like:

(function($, window, undefined){
    var options, methods = {
        init : function(opts){

            options = $.extend({}, {
                width   : 800,
                height  : 600,
            }, opts);

            return this.each(function(){
                data = $(this).data('prodigal');
                if(!data){
                    $(this).data('prodigal', options).on('click', openl);
                }
            });
        },
    },
    openl = function(){
        console.log(options);
    };


    $.fn.prodigal = function(method) {
        // Method calling logic
        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.prodigal' );
        }
    };
})(jQuery)

And I call it like:

$('.view_title_images').prodigal({width: 500});
$('.glglg').prodigal({ width: 600 });

The problem is when I output the options in openl I actually get both selectors showing a width setting of 600.

Up until recently I stored element specific info on the elements data tag: $(this).data('prodigal', options) and then acessed that data in every function I made so that openl would have a line at the top that goes like: options = $(this).data('prodigal').

I did try and use public methods instead but I couldn’t seem to bind those public methods in the $(this).data('prodigal', options).on('click', openl); line, it kept producing errors.

Should I still be trying to store my settings in my elements data tag or is there something I am missing about building jQuery plugins? How do I manage settings in a plugin?

This doesn’t seem to be clearly covered by previous topics I have searched for.

  • 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-16T01:22:31+00:00Added an answer on June 16, 2026 at 1:22 am

    To answer this to a degree, as @Matt says:

    Storing options in data() is the usual approach.

    And I have now come to the realisation I was doing nothing wrong.

    The reason for this question was because, in the wild, I have seen many plugins created in many ways.

    Due to a comment that is kind of linked: Difference in $.extend calls in a plugin? I have been able to get hold of a set of “good” design patterns that I can use to suite my needs (that are not in the documentation): http://jqueryboilerplate.com/ as kindly provided by @Marcus in the linked comment.

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

Sidebar

Related Questions

I have code that looks like this: var baseClass = function() { // CODE
I have some code that looks like this: var MyObject = function () {
Inside my .aspx I have some JSON code that looks like this: function someFunctionName()
I have some code in a couple of different functions that looks something like
I have code that looks like this: obj.foo(); // obj might, or might not
I have code that looks like this: template<class T> class list { public: class
I have code that looks like the following: //unrelated code snipped resolver.reset(new tcp::resolver(iosvc)); tcp::resolver::query
I have code that looks like the following: <form id=MyForm name=MyForm method=post action=index.php> <input
I have code that looks like this: class T {}; class container { const
I am currently working on a project where I have code that looks like

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.