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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:28:55+00:00 2026-06-02T15:28:55+00:00

Short question: Let’s say we have jQuery included. Will this function execute faster …

  • 0

Short question:

Let’s say we have jQuery included. Will this function execute faster …

var example1 = (function($, jQuery) {
    return function() {
        // do something
    }
})()

… than the following one:

var example2 = (function() {
    return function() {
        // do something
    }
})()

?

In the first one the jQuery object will be undefined, in the second one it will be inherited. So the second one should be more expensive?

What is the best way to improve speed and get rid of inherited variables that decreases performance?

jsPerf test: http://jsperf.com/objinheritance

  • 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-02T15:29:00+00:00Added an answer on June 2, 2026 at 3:29 pm

    As ECMAScript defines, reference resolution is a inner-to-outer lookup process, so in the first example, the $ variable is 1 step from your code, and in the second example, while $ resides in global scope, it is at least 2 steps away, which cause extra lookup overhead.

    However, in real world, modern javascript engines (such as V8) doesn’t implement reference resolution the exactly same way which ECMAScript states, they have an approach to flattern the scope chain, in other words, for most code, all variables can be referenced in a single step, no lookup overhead at all.

    Conslusion: they are really same to each other.

    PS: as well as the scope chain, javascript engines have quite the same optimization on prototype chain, so there is also no need to worry about a property lookup overhead.

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

Sidebar

Related Questions

I have a short question, let's assume I have a TabBarController with 3 Tabs
I have a question on the xmlhttprequest object. Let's say I create a xmlhttprequest
Intro Let me apologise upfront for the long question. It is as short as
This question is sort of a follow-up to my original question here . Let's
Short question: Is it possible to do a redirection, say when a user isn't
Short question: Is the parent of an entity group included in that entity group
Short version of question: see title Long version of question: I've used jquery's show()
The question is quite theoretical. Let's say you're implementing a normal (or small or
Short Question I have a 50dip by 40dip button in my Android XML layout.
I got a small question with a big background. Let me ask a short

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.