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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:29:32+00:00 2026-06-13T11:29:32+00:00

The Issue Cannot believe I could not find anything on this around the net,

  • 0

The Issue

Cannot believe I could not find anything on this around the net, maybe I am searching for the wrong thing…

There is probably little or no difference at all, but as I am trying to optimize my code as best I possibly can, I feel it is worth asking.

Very simply, I would like to know whether defining and running a method in an object processes faster than defining and running a function globally.

Examples

Consider this:

(function($){  
    $.fn.test = function() {  
        // do something here
    };  
})(jQuery);

And this:

function test(){
    // do something here
}

My Question

Which of the above is faster and why? If there is no difference in speed then which would you advise using?

Thanks in advance

UPDATE 1

As it may be relevant, I feel it is necessary to explain why I am asking this question. I have a library that I have written over the years that contains a large variety of functions. As there are so many of them, I want to know whether they would run faster if I was to extend the jQuery object, or keep them as they are?

  • 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-13T11:29:32+00:00Added an answer on June 13, 2026 at 11:29 am

    In theory, you just need to count the number of objets that must be searched to determine which will be faster. Variables are resolved against the scope chain, the script engine must first search the function’s execution context, then the outer contexts, and finally the global context.

    Property resolution must first find the object on the scope chain, then the property on the object or its [[Prototype]] chain.

    But in practice, compiler optimisation means the above simplistic analysis is will be wrong as often as it is right, and also deliver different results in different browsers for different cases.

    Generally, such optimisations deliver minuscule changes in performance and should not be considered purely for performance reasons. Design objects and methods for whatever makes sense for your application architecture, ease of maintenance and logical grouping.

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

Sidebar

Related Questions

I am stuck on this issue and cannot seem to find a way around
This seems like such a simple issue but I cannot find an elegant solution.
I have been researching this issue pretty extensively and cannot seem to find an
Yes, it's this question again... Somehow, I cannot get this issue resolved. Believe it
There is an issue that I cannot solve, I've been looking a lot in
I already have this issue but I cannot remember how to solved it. (I
OK so I have an xslt issue that I cannot seem to solve. This
Here is another issue I cannot quite believe hasn't been resolved yet... I am
I am going to ask you this question here since I cannot find answer
I am having an xslt issue that I cannot seem to solve. Right now

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.