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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:43:13+00:00 2026-05-24T23:43:13+00:00

I realise that it is useful (for performance reasons) to do something like… function

  • 0

I realise that it is useful (for performance reasons) to do something like…

function Abc(a, b, c) {
    var window = window;

So when the code accesses window, it doesn’t need to go up the scope chain to finally find window. The same can be done for document, navigator, etc…

But I’m in the process of rewriting some of the MobiScroll jQuery plugin and found this…

function Scroller(elm, dw, settings) {
    ...
    var elm = elm;
    var dw = dw;
    ... 

What are the advantages of reinitialising elm and dw to point to their argument variables ?

I’ve read a lot about accessing arguments being costly, but never read anything about why this might be good practice.

What are the benefits in doing this?

In the past, I’ve deliberately removed this construct from MDN documentation.

  • 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-24T23:43:14+00:00Added an answer on May 24, 2026 at 11:43 pm
    > function Abc(a, b, c) {
    >     var window = window;
    

    So when the code accesses window, it doesn’t need to go up the scope
    chain to finally find window.

    I don’t think that’s the reason. For a function declared in global scope, resolving an identifier locally versus globally will be insignificanly faster (and perhaps slower depending on the browser).

    Scripts may use something similar to the above to ensure window refers to the expected window object and not some other window on the scope chain, e.g.

    var fn = (function(window) {
    
      // In here window is unequivocally a reference to the global object
    
    }(this));
    

    In the second example:

    > function Scroller(elm, dw, settings) {
    >     ...
    >     var elm = elm;
    >     var dw = dw;
    >     ...
    

    Declaring the variables is complete waste of time. Putting an identifier in the formal parameter list of a function declaration or expression is equivalent to declaring it localling with var. Declaring such identifiers as local variables has no effect whatever.

    There was an early version of Safari that had an issue with formal parameters that weren’t passed a value, but that was a long time ago and was only an issue in one very specific case.

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

Sidebar

Related Questions

I realise that the view/controller stuff will be different between Mac and IPhone apps
I realise that this is a very basic question, but it is one which
I realise that you can open the google maps app ready for directions by
I realise there might be similar questions but I couldn't find one that was
I realize that evaluating an array in Perl in a scalar context is useful:
Recently I came across a gcc extension that I have found rather useful: __attribute__(cleanup)
Closures are an incredibly useful language feature. They let us do clever things that
I am learning how to use Zend framework and realise that the action helper
I'd like to write a simple wrapper for the python list type that forces
I have a large code base that resides on a unix server, and for

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.