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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:59:43+00:00 2026-05-18T01:59:43+00:00

In the following JQuery UI widget the author has used extend to include two

  • 0

In the following JQuery UI widget the author has used extend to include two more functions in $.ui.autocomplete, why? Is this a JQuery specific pattern or is it something I could be considering in plain JS?

$.extend( $.ui.autocomplete, {
escapeRegex: function( value ) {
    return value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
},
filter: function(array, term) {
    var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
    return $.grep( array, function(value) {
        return matcher.test( value.label || value.value || value );
    });
}
});

https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.autocomplete.js#L385

  • 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-18T01:59:43+00:00Added an answer on May 18, 2026 at 1:59 am

    There is no reason to use it and in reality it will be slower than doing it the manual regular JS way. Often jQuery developers have a problem in that they only know how to use jQuery and not regular javascript. jQuery’s extend function is a recursive actually quite slow beast compared to managing things yourself.

    *edit * Since people do not want to seem to accept this answer, let me show why there is no reason.

    If you look at jQuery’s code on github here: https://github.com/jquery/jquery/blob/master/src/core.js you will find the definition of jQuery.extend on line 313.

    First of all, let’s look at what is necessary to do the non-jQuery extend way.

    $.ui.autocomplete.escapeRegex = function() {}
    $.ui.autocomplete.filter = function() {}
    

    Two definitions, no function calls. Very simple and fast code.

    This is what jQuery does if you use extend.

    On line 315 we see a quick little test to organize arguments a bit.
    Next we have another little IF statement with possible code execution.
    Next is another IF with a function call inside of the if.
    Next is another IF.
    We then enter a FOR loop for each of the arguments, in our case two rounds.
    On each pass first there is a check for null values, needless in our situation since we made the functions ourselves.
    Now we have a FOR IN loop which by nature is very slow due to having to look up each of the items inside the object map instead of just iterating over an iterator.
    Now we finally copy one of our functions in to jQuery!
    Do another check to make sure we don’t enter an infinite loop…
    For our case this time we just do one more little IF check.
    And the loop repeats until things are done.

    Therefore this method is far slower than directly copying in to the jQuery object itself. A common problem for people that use API’s is that even though the function usage might be simple and look fast and easy, the internals can be very complex and slow compared to doing things yourself.

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

Sidebar

Related Questions

I have stolen/found/used/written and edited the following widget of jQuery for a auto-completing dropdown.
The following two forms of jQuery selectors seem to do the same thing: $(div
Is it possible to create the following behavior with one or more existing JQuery
I am using the following jquery code: $(#top ul li.corner).mouseover(function(){ $(span.left-corner).addClass(left-corner-hover); $(span.right-corner).addClass(right-corner-hover); $(span.content).addClass(content-hover); }).mouseout(function(){
i have the following jquery code. basically i will have several overlapped divs and
I have the following JQuery code that worked perfect in C#/Asp.net 2.0 to call
I have the following JQuery code which does similar functionality like Stackoverflow where the
Let's say I have the following jQuery AJAX call: $.ajax({ type: POST, url: MyUrl,
I use the following for a jQuery link in my <script> tags: http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js Is
while exploring jQuery I came up with the following weird script. I don't see

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.