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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:12:17+00:00 2026-06-15T09:12:17+00:00

At this link , Mozilla explains what ‘this’ references in the following way: In

  • 0

At this link, Mozilla explains what ‘this’ references in the following way:

In general, the object bound to this in the current scope is
determined by how the current function was called, it can’t be set by
assignment during execution, and it can be different each time the
function is called.

Under normal circumstances, I understand this and how its reference changes.

The book Pro JavaScript Design Patterns says the following about lexical scope

JavaScript is also lexically scoped, which means that functions run in
the scope in which they are defined, not the scope they are executed
in.

So ‘this’ depends on how the current function was called, while lexical scope means functions are run in the scope in which they are defined.

My question is, can this ever be part of the lexical scope, and, if so, how do I understand the fact that this depends on how the current function was called, while lexical scope restricts functions to the scope in which they are defined.

  • 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-15T09:12:18+00:00Added an answer on June 15, 2026 at 9:12 am

    Just think of them as separate concerns.

    • The variable scope of a function will never change.

    • The value of this will change depending on how the function is invoked. Given the same function, different invocations give the same function a different this.

      var foo = (function() {
                    var bar = "bar";
                    return function() { console.log(bar, this); };
                })();
      
      foo();    // the default `this`
      
      var someObj = {some: "object"};
      foo.call(someObj);    // `this` is someObj
      
      var aDiffObj = {aDiff: "object"};
      foo.apply(aDiffObj);  // `this` is aDiffObj
      
      var anotherObj = {another: "object", foo:foo}; 
      anotherObj.foo();     // `this` is anotherObj
      
      var binderObj = {binder: "object"};
      var bound = foo.bind(binderObj);
      bound();              // `this` is binderObj
      
      new foo(); // `this` is a new object being constructed, 
                 //      which has the prototype of `foo` in its prototype chain
      

      All the invocations have access to the bar variable, but a different this value.

    So given the current function syntax in ECMAScript, this will never be taken from the lexical scope, but will always be assigned a value based on the invocation.

    There’s a new function syntax in the works that will likely have a lexical this, but that’s sometime in the future.

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

Sidebar

Related Questions

This link shows how to inject JavaScript code to WebView object in Android. However
following this link i was able to load and read pixels from a .gif.
i am using this function to get link of page which refered current page
In the following example (from Mozilla's site): <div style=color:darkred> The color of this text
Take a look at this URL: http://download.mozilla.org/?product=firefox-9.0.1&os=win&lang=nl It is the direct link to download
naturalHeight and naturalWidth property of HTMLImageElement object is not mentioned in mozilla website Link
I'm looking at this question and in it is a link to http://hacks.mozilla.org/2011/03/the-shortest-image-uploader-ever/ which
This link http://ajaxcontroltoolkit.codeplex.com/releases/view/11121#DownloadId=28808 shows a popup on which one has to agree before being
This link shows you that jQuery uses (new Function(return + data))(); for older browsers,
This link states that all columns that are nullable should be added to the

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.