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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:29:44+00:00 2026-06-03T23:29:44+00:00

I have build a little function which returns a jQuery plugin applied to a

  • 0

I have build a little function which returns a jQuery plugin applied to a certain element, as in the following example:

var initiate_shop = function(shop_navigation, options, callback) {

    var default_settings = {
        containerID     : "",
        first           : false,
        previous        : false,
        next            : false,
        last            : false,
        startPage       : 1,
        perPage         : 8,
        midRange        : 15,
        startRange      : 1,
        endRange        : 1,
        keyBrowse       : true,
        scrollBrowse    : false,
        pause           : 0,
        clickStop       : true,
        delay           : 50,
        direction       : "auto",
        animation       : "fadeInUp",
        fallback        : 400,
        minHeight       : true,
        callback        : function(pages, items){
            if(typeof callback == 'function') {
                callback.call(this);
            }
        }
    };

    var settings = $.extend(default_settings, options);

    return $(shop_navigation).jPages(settings);
};

My question would be, how could I use that initiate_shop function like this:

$("shop_navigation").initiate_shop( ... );

Instead of using it like this:

initiate_shop(shop_navigation, ... );

Also, how can I define arguments for the callback function, in my situation I have two objects as arguments for the callback function ?

  • 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-03T23:29:45+00:00Added an answer on June 3, 2026 at 11:29 pm

    Looks like you’re trying to create a jQuery plugin. Extend the $.fn object with your function, and you will be able to access your container with the this keyword from within the function.

    $.fn.initiate_shop = function(options, callback) {
        ...
        return this.jPages(settings);
    };
    

    Note that your call $('shop_navigation') is not a valid selector, unless you’re looking for an element named shop_navigation. Did you intend to write $('#shop_navigation')?

    The reason I’m asking is that you might equally well write

    $('.shop_navigation').initiate_shop(options, callback);
    

    It is up to your plugin to deal with supporting multiple elements being passed in this.


    The way you’re currently calling your callback, using .call, is useful if you want to specify what the context, i.e. the this keyword, is in your callback function.

    Consider that your callback looks like this:

    var callback = function(pages, items) {
       console.log(this);
       console.log(pages);
       console.log(items);
    };
    

    If you don’t care what the this keyword is within your callback function, you could simply call the function as

    callback(pages, items);
    

    If you want to manually set the calling context, you may use .call or .apply. You can still pass arguments to the function:

    // first argument defines calling context
    // all others passed as arguments to function
    callback.call(this, pages, items);
    

    or

    // first argument defines calling context
    // second argument defines entire arguments collection
    callback.apply(this, [pages, items]);
    

    In your case, if callback variable will only ever be a function, or undefined, and you’re not adding any additional logic, as it is right now, you’d get away with just:

    var default_settings = {
        ...
        callback: callback
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day. I have little usage of Flash CS4, however i have to build
I have this nice little MSBuild-based daily build setup that I use on my
I have a site I'm trying to build and I've hit one little snag
I have build a webapplication using ASP.NET MVC and JQuery. On my local machine
I'm trying to build a little calendar in JavaScript. I have my dates working
I have a little problem understanding how to to the following in Haskell: Lets
I have built a little web application with several *.js files. I am using
We have a little in-house LMS with courses built in Flash. Scores are updated
I have a little dilemma on how to set up my visual studio builds
I have build server inside our domain (and it needs to be because it

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.