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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:41:06+00:00 2026-05-12T05:41:06+00:00

In Javascript OO, when should I use the this keyword? Also, if I want

  • 0

In Javascript OO, when should I use the this keyword?

Also, if I want to call a method of a class from another method of the same class, should I use this or just the name of the function? E.g is this correct?

function Foo()
{
   this.bar= function()
   {
      alert('bar');
   }

   this.baz= function()
   {
     this.bar(); //should I use this.bar() or just bar()?
   }
}
  • 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-12T05:41:06+00:00Added an answer on May 12, 2026 at 5:41 am

    When it comes to “object-oriented” JavaScript, here’s a nice guide Mark Dickinson here on SO linked to: Private Members in JavaScript. It does go into detail about some other stuff you don’t really need now, but once you understand how JavaScript works, you’ll see that it’s quite different from your ordinary object-oriented language when it comes to things like what this really means.

    I’d say that in your case, you should definitely use this, but maybe your functions should be in the prototype part of your “class” (this avoids redefining the function every time a new instance is created.)

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

Sidebar

Related Questions

I want to use this piece of JavaScript so that, depending on the browser
According to this article it should be a Javascript 2.0 way to define class.
I do know that in javascript, when you use this keyword inside a function,
The following javascript should setup an interval so a new item from the list
Should this code not work? I actually have no idea how to use this
javascript noob here. So I'm trying to use this s3 uploader jQuery example here
Can someone please guide me regarding which touch framework (javascript) I should use to
Possible Duplicate: What is the 'new' keyword in JavaScript? creating objects from JS closure:
I am working with session timeout in javascript. I use this code for the
I want to use a PHP variable as a javascript variable - specifically I

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.