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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:41:36+00:00 2026-05-25T18:41:36+00:00

I’m writing a plugin that will display a little helper when called for. It’s

  • 0

I’m writing a plugin that will display a little helper when called for. It’s supposed to be initiated like this:

$(el).santasLittleHelper([options])

The plugin then have some “events” just like the jquery UI has and they should be triggered like this:

$(el).santasLittleHelper('evetnName', [options])

I have a prototype working but I have a few concerns about future problems with my structure. Flooding the memory or having other issues with variable and function scopes when I keep on working on it. Here is an outline:

(function($) {

$.fn.santasLittleHelper = function(p1, p2) {

    return this.each(function() {
        var o = {
            showSpeed: 50,
            hideSpeed: 50,
            duration: 5000,
            delay: 0
        }
        var el = $(this);
        function init() {
            console.log('init 1');
        }
        var events = {
            show: function(opt) {},
            hide: function(opt) {},
            pulse: function(opt) {}
        }
        if(p1 == undefined) {//This is obviously the init call
            init();
        }
        if(typeof(p1) == 'object') {
            //Correctly added parameters would then mean that p1 is options
            //and is the only parameter added so we store the options and init
            $.extend(o, p1);
            init();
        }
        if(typeof(p1) == 'string') {
            //This is a call to an "event".
            //call the "event" function and supply possible options as arg
            events[p1](p2);
        }            
 });
}

})(jQuery);

Options can be supplied for each event call but should in that case only be available in that events function scope. This is because I might want the helper to do something out of the mental box I created him in by supplying options in the init call.

Will this approach fill up the memory a little by each call to $(el).santasLittleHelper(‘event’) because of the declared variables in the beginning of the code?

I think it looks clean and understandable, but can improvements be done?

  • 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-25T18:41:37+00:00Added an answer on May 25, 2026 at 6:41 pm

    According to practices described here, it seems to me that you’re doing it right, but I would try if possible to make o and events independent of each (declare it before and pass as optional parameter if override is needed else use unique declared outside of each?)

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I need a function that will clean a strings' special characters. I do NOT
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

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.