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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:12:05+00:00 2026-05-20T20:12:05+00:00

I get confused about ‘ this ‘ keyword in the following codes, there are

  • 0

I get confused about ‘this‘ keyword in the following codes, there are two ‘this’:

var Foo = function(string){
  this.name=string // 1st-this
}

Foo.prototype.get_name = function(){
  return this.name // 2nd-this
}

var myFoo = new Foo('John')

the_name=myFoo.get_name()

‘the_name‘ is equal to ‘John’, the prototype method get the name by return this.name. But can anyone explain to me the 1st-this and 2nd-this, what do they stand for?

  • 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-20T20:12:05+00:00Added an answer on May 20, 2026 at 8:12 pm

    In Javascript, the value of this is dependent on the way you call the function.

    There are 5 ways to call a function in JS, and they all have effect on this:

    1. new Foo(); <= here, you’re creating a new object, and this will reflect that new object
    2. Foo(); <= here, you’re calling the function as-is, and this will be the global object(!)
    3. var obj = { foo: Foo };
      obj.foo();
      <= here, you’re calling the function as a method of obj; this will be obj
    4. Foo.call(thisObject, arg1, arg2); <= here, you can specify the value of this in the first argument
    5. Foo.apply(thisObject, [args]); <= here, you can specify the value of this in the first argument

    In 4 and 5, the difference between call and apply is that with call, you need to pass all the arguments separately, whereas with apply, you can pass an array containing all the arguments.

    Note that in my example 2 above, the function should have been called foo instead of Foo. Since it’s impossible to know off-hand whether a function is supposed to be called with new or not, the consensus is to start the function name with a capital letter if it’s a constructor (and should be used with new); otherwise, it should start with lowercase.

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

Sidebar

Related Questions

I am really confused about how I can do this. I need to get
I get a compile error, which I'm slightly confused about. This is on VS2003.
OK, I always get confused about this. Let's say I have this code. Public
I am confused about selecting two approaches. Scenario there are two tables Table 1
I'm confused about the difference between these two things: $env:path And function path {$env:path}
I know, this is basic stuff. But I get confused about this all the
I always get confused when I am about to use a bit map to
I am confused about the terms overestimation/underestimation. I perfectly get how A* algorithm works,
I am a little confused about how I set and get the instance variables
I'm still trying to get a hang of Perl's OOP features. I'm confused about

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.