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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:15:22+00:00 2026-06-09T00:15:22+00:00

I am authoring a plugin which instantiates a map. The map would then provide

  • 0

I am authoring a plugin which instantiates a map. The map would then provide a function to move to another place on the earth.

The script makes the map just fine. However I can’t “tack” the function on the element, to be used by another plugin in a callback.

Here’s the approach I tried; in plugin:

(function($){
  $.fn.mapDo(options){
    map = new BlahMap(this.get(0));

    this.moveTheMap = function(place){
      map.moveItToThat(place);
    }; // nope.
  }
})(jQuery);

Then, in view:

$(map).mapDo();

$(otherElement).otherControl({
  callback: function(place){
    $(map).moveTheMap(place); // moveTheMap is not there on $(map)!
  }
};

The Question

How do I add a function to the map jQuery or DOM element, if possible? If not, how can I provide that kind of functionality?

More importantly, am I going the right way here by separating the things that way? I’m a bit of a neophyte to Javascript, how are these tasks usually done while still keeping the components apart?

While that’s the stab I took at it, more generally, I struggled with the concept of outputting things from a jQuery plugin while maintaining chainability. In this case, what I am trying to do is to output a callback from the plugin that will work on the called element later in the execution.

  • 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-09T00:15:25+00:00Added an answer on June 9, 2026 at 12:15 am

    Plugins normally only add one method to the jQuery prototype, and the method calls to the plugin’s instances are done with strings.

    (function($) {
        $.fn.mapDo = function(options) {
            var args = [].slice.call(arguments, 1); //Get all the arguments starting from 2nd argument as an array
            return this.each(function() {
                var $this = $(this),
                    instance = $this.data("map-instance");
                if (!instance) {
                    $this.data("map-instance", (instance = new BlahMap(this, options)));
                }
                if (typeof options == "string") {
                    instance[options].apply(instance, args);
                }
            });
        };
    })(jQuery);
    
    $(elem).mapDo( "moveTheMap", place ); //This would also instantiate the plugin if it wasn't instantiated
    

    Here’s jsfiddle showing it in action:

    http://jsfiddle.net/X8YA8/1/

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

Sidebar

Related Questions

i'm currently exploring jQuery's plugin authoring and: var methods = { init : function(options)
According to the jQuery plugin authoring guidelines , a basic plugin structure would look
I defined my plugin base on http://docs.jquery.com/Plugins/Authoring (function( $ ){ var methods = {
I'm authoring a jQuery plugin in which one of the methods that I'd like
Following the good jQuery Plugins/Authoring instructions I have a little question (function($){ // Default
I would like to have a workflow create a task, then email the assigned
I am developing an application which users authlogic for authentication. I would like some
I'm working on a small app that makes use of the jQuery plugin Fullcalendar.
I have a basic plugin written according the jQuery authoring guide . This plugin
Some time ago I had a problem with Uploadify plugin for which I did

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.