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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:29:49+00:00 2026-06-12T14:29:49+00:00

This question is in reference to this jQuery limit plugin . Here’s the source:

  • 0

This question is in reference to this jQuery limit plugin. Here’s the source:

(function($){ 
    $.fn.extend({  
        limit: function(limit,element) {
            var interval, f;
            var self = $(this);

            $(this).focus(function(){
                interval = window.setInterval(substring,100);
            });
            $(this).blur(function(){
                clearInterval(interval);
                substring();
            });

            substringFunction = "function substring(){ var val = $(self).val();var length = val.length;if(length > limit){$(self).val($(self).val().substring(0,limit));}";

            if(typeof element != 'undefined')
                substringFunction += "if($(element).html() != limit-length){$(element).html((limit-length<=0)?'0':limit-length);}"

            substringFunction += "}";
            eval(substringFunction);
            substring();            
        } 
    }); 
})(jQuery);

Now I may just be nitpicking here… but maybe I’m missing something. Here are my questions/concerns:

1) What is the purpose of creating the substring function in a string and then eval‘ing it? Looking through, it seems like the extension would work perfectly fine if the function was initialized normally.

2) I don’t like that it uses a setInterval to execute the substring function. Wouldn’t a keypress or similar event be the better and more logical way to do this? Also, I believe this to be the cause of (or at least enabling) the ‘flickering text’ bug that is referenced in the v1.2 change log (No, it isn’t fixed).

3) Why is the variable f initialized? It is never used or referenced.

4) Also, this isn’t a chainable method, and as a jQuery extension, it should be. I’m not too familiar with writing jQuery extensions, but this can be accomplished by return this; at the end of the method, correct?

It seems like this is just a case of poor programming, but I’d like to get an outside opinion.

  • 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-12T14:29:50+00:00Added an answer on June 12, 2026 at 2:29 pm

    1) I agree. Looks like he doesn’t understand closures to me.

    2) It’s hard to predict exactly which events might change the contents of the textbox. Keypresses are obvious, but maybe mouse events could also do it. It could also be updated by other Javascript functions.

    3) I have a couple of guesses: a) He was using it to hold the callback function when he was trying to get the closure to work, and didn’t remove the declaration when he switched to the eval kludge; b) it was supposed to hold the substring function string, but he made a mistake and called it substringFunction when he assigned it (notice that he forgot the var declaration there).

    4) True.

    Just because someone posts their code to a web site doesn’t mean they’re an expert.

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

Sidebar

Related Questions

Reference: This is a self-answered question. It was meant to share the knowledge, Q&A
With the reference to this question:- JavaScript -Change CSS color for 5 seconds Working
In reference with this question We have a header with a date picked component
EDIT: This question is about finding definitive reference to MySQL syntax on SELECT modifying
Somebody ask me this question today . What is the need of reference in
I'm using Alberto Santini's solution to this question to get a spiral grid reference
This is with reference to the below question: Execute program from within a C
This might be a silly question but does ARC (automatic reference counting) interact with
this may be a stupid question but when I add a reference to my
In reference to this answer to a Stack Overflow question : what is bench-testing

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.