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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:17:23+00:00 2026-06-10T03:17:23+00:00

In some of my Javascript objects I find that my this pointer is correct

  • 0

In some of my Javascript objects I find that my this pointer is correct – these are new Func() -type objects – when created, but in the assigned methods it can be wrong.

function Confused() {
   console.log("checking",this==window,"is always false");
   this.method = function() {
       console.log("checking",this==window,"is true for some funcs but not others");
   };
};

On some calls to (new Confused()).method() – it seems to have lost it’s this pointer. The times this happen seem dependent on the function, rather than random; its something in the code around how I’m creating classes that is causing this.

An example is online at http://williame.github.com/barebones.js/ and the member callback G3D._file_loaded has a wrong this pointer when called sometimes.

Why, and how do I fix it?

  • 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-10T03:17:24+00:00Added an answer on June 10, 2026 at 3:17 am

    There are 4 ways to use a function in Javascript
    what each of these does is change what the content of this is :

    • function calls: this = global object (window in browser)
    • method calls: this = object it is called from.
    • constructor calls: this = new object you are creating.
    • call/apply calls: this = object you passed.

    In your case this == window when you call the function directly (Confused()) but if you call using new (new Confused()) then it will be the new object you are creating.

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

Sidebar

Related Questions

I am working on a Javascript object that contains some YUI objects. The key
I am doing some exercises in my object-oriented javascript book, I notice that this:
First let me preface this question by saying that I'm fairly new to Javascript.
I'm currently building an JavaScript project that uses NodeJS and some objects are shared
This is not a question specific about some javascript detail but I'm looking for
I'm pretty sure that many people have thought of this, but for some reason
i have a object in javascript and some already defined functions. but how can
I'm calling some JavaScript from within my PHP code, but I want the second
I've got some javascript that I want to attach to forms and to HTML
Now I have googling this a lot, but I cant seem to find what

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.