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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:12:07+00:00 2026-05-15T05:12:07+00:00

There are quite a few ways to write plugins i.e. here’s a nice example

  • 0

There are quite a few ways to write plugins i.e. here’s a nice example and what I’ve seen quite a lot of lately is the following code pattern and it’s used by Doug Neiner here;

(function($){
   $.formatLink = function(el, options){
    var base = this;
    base.$el = $(el);
    base.el = el;
    base.$el.data("formatLink", base);
    base.init = function(){
       base.options = $.extend({}, $.formatLink.defaultOptions, options); 
       //code here
    }                 
    base.init();
   };

   $.formatLink.defaultOptions = { };

   $.fn.formatLink = function(options){
      return this.each(function(){
       (new $.formatLink(this, options));
      });
   };
})(jQuery);

So, can anyone tell me the benefits of using the pattern above rather than the one below. I can’t see the point in calling the $.extend function for every element in the jQuery stack (above), where the example below only does this once and then works on the stack.

To test it I created two plugins, using both patterns, which applied styles to about 5000 li elements and the code below took about 1 second whereas the pattern above took about 1.3 seconds.

(function($){
   $.fn.formatLink = function(options){
       var options = $.extend({}, $.fn.formatLink.defaultOptions, options || {});

       return this.each(function(){
        //code here
       });
    });

$.fn.formatLink.defaultOptions ={}
})(jQuery);
  • 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-05-15T05:12:08+00:00Added an answer on May 15, 2026 at 5:12 am

    I know Doug used this format when writing Anything Slider, I think it was done to expose internal functions and make it easier to call them after an addon has been initialized. For example in Anything Slider you can go to a particular slide two ways:

    1. Use $('.anythingSlider').anythingSlider(2); which is intented for external links. But this method actually uses the method below to perform the action.
    2. A second way, which shows how you can access the sub function through the data is done like this: $('.anythingSlider').data('AnythingSlider').gotoPage(2);

    Maybe there are easier/better ways, but I would think the author has the best explaination/reasoning for this method. So @Doug Neiner (if that works), give us an idea 🙂

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

Sidebar

Ask A Question

Stats

  • Questions 531k
  • Answers 531k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you would like to match a glob recursively when… May 16, 2026 at 11:59 pm
  • Editorial Team
    Editorial Team added an answer Update July 2017: From ADT Plugin page, the question must… May 16, 2026 at 11:59 pm
  • Editorial Team
    Editorial Team added an answer Perhaps you should start from this book WPF Control Development… May 16, 2026 at 11:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I looked through the related questions, there were quite a few but I don't
I've read quite a few posts that are very similar to the question I'm
currently we're running quite a few applications on our WebSphere Portal Server, and most
I have an app that uses quite a few graphics in it. When I
I have an application that's locked down using forms authentication. There are few nightly
To give a little background, I'm writing (or am going to write) a daemon
Can anyone either point me to (or provide here) a clear, step-by-step approach that
Is there a way that has better performance than the other when appending a
When you want to print a bunch of variables in Python, you have quite
Apologies if this is a very simple question; I don't use XSLT very much

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.