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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:41:24+00:00 2026-05-11T07:41:24+00:00

I am asking this from a language design point of view. So I am

  • 0

I am asking this from a language design point of view. So I am trying to find out

  1. What is the rationale for the behavior of this?
  2. To what degree the behavior of this was a mistake, or could be improved upon?

To clarify why I’m uneasy about this, consider this example:

var a = {}; a.f = function(){ return this; } var f = a.f; // f() != a.f() 

Note how easily the object to which f() belong is lost: separated from a, this becomes the global object (window for browsers).

Now consider:

var newA = function(){     var self = {};     self.f = function(){ return self; }     return self; }  var a = newA(); var f = a.f; // f() == a.f() ! 

Without using this at all, we are able to establish and maintain the object context regardless of where or how the method is used. I can’t help but think that, with the power that closures provide, this becomes superfluous, and perhaps even a little dangerous…

I’m not on some vendetta against this, or looking to start an argument; I’m merely trying to better understand it. I do appreciate that ‘this’ can be useful, but recognize that it can be confusing as well… Certainly confusing to beginners, and perhaps to experts as well in sufficiently obscure cases.

And yet, it remains a heavily-used and seemingly well-respected part of the language, in a time when other core aspects of the language seem fair game for shunning (i.e., Crockford and with or new). What am I missing then, that makes this indispensable?

  • 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. 2026-05-11T07:41:24+00:00Added an answer on May 11, 2026 at 7:41 am

    You seem to be expecting this to behave as it does in certain OO languages, where it always refers to the object a method belongs to.

    But in JavaScript, a function can be attached to multiple objects, or no object at all. In your example, you’ve written a function intended to be used in the context of one specific object… But nothing prevents me from taking that function and attaching it to any other object. That’s just the nature of the language – functions are first-class, object membership is optional.

    Therefore, this refers to the context in which a function is called. Right now, that’s either an arbitrary object (specified via ., .apply, or .call()) or the global object. In future versions of the language, it will refer to the context in which the function was defined: the global object for global functions, the outer this for inner functions; you can view this as a correction of a design flaw, as in practice being able to refer to the global object using this was not particularly useful.

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

Sidebar

Related Questions

I am asking this question from an architectural point of view. I have been
When using this code (simplified for asking): var rows1 = (from t1 in db.TABLE1
I searched before asking this question. I didn't find an answer probably because I
I feel bad for asking this, but I can't find any answer on the
I'm just asking this out of curiosity : Is there any tool that can
I am thinking about asking this question from sometime.. Now I am finally asking
NOTE: I am asking this question out of inquisitiveness and not questioning the importance
Before asking this i did A LOT of searching on the net. I just
In asking this question, I'm looking for either better understanding of the situation or
I am finally asking this question as I have never actually found an answer.

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.