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

  • Home
  • SEARCH
  • 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 8254657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:16:02+00:00 2026-06-08T01:16:02+00:00

I’m trying to create a jQuery Plugin using there name spacing system, so this

  • 0

I’m trying to create a jQuery Plugin using there name spacing system, so this is a small example of what i have

(function($){
var jScrollerMethods = {
    init:function(config){
        this.settings = $.extend({
            'option':'value'
        }, config);
    },
    getOption:function(){
        return this.settings.option;
    }
}

$.fn.jScroller = function(call){
    if ( jScrollerMethods[call] ) {
      return jScrollerMethods[call].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof call === 'object' || ! call ) {
      return jScrollerMethods.init.apply( this, arguments );
    } else {
      $.error( 'Method ' +  call + ' does not exist on jQuery.jScroller' );
    } 
}

$(".selector").jScroller({'option':'newValue'});
var opt = $(".selector").jScroller("getOption");

})(jQuery);

the opt variable does not work and it should not work as when declaring functions like that the this points to the function E.G into the init:function(){.. this points to the function set to init so how do i make it so that the getOption function can access the settings but these can’t be saved to the window as there could be more than one instance of the jScroller running on differing selectors i just get seem to find or figure it out

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

    You need to create a unique options object for each instance, and you need to store it with the instance. jQuery data() is great for this. This uses Crockford’s Object.create() which you may have opinions about.

    if (typeof Object.create !== 'function') {
      /* 
         Function: create
    
         create a new instance of an object using an existing object as its prototype
    
         Parameters:
            o - the object serving as the new prototype
    
         Returns:
            a new object
      */         
      Object.create = function (o) {
         function F() {}
         F.prototype = o;
         return new F();
      };
    

    }

    Then in your init function, add something like this:

    return this.each(function() {            
        var self = this,
        $this = $(this),
        data = $this.data('jScroll'),
        opts = Object.create(options);
    
        if (!data) {
            $this.data('jScroll', {
              options: opts, // this is the options object that you'll access later
              element: this // you may not need this
            });
        }
    }); 
    

    and your getOptions method executes this:

    var data = this.data('jScroll');
    if (data.options[options]) { return data.options[options] };
    

    I do the settings merge before I call init:

    } else if ( typeof call === 'object' || ! call ) {
        if (call) { $.extend(settings, call) } // this expects a settings variable defined with defaults
        return jScrollerMethods.init.apply( this, call );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to

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.