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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:58:17+00:00 2026-05-25T15:58:17+00:00

I have the following which is a simplified version of what I have: function

  • 0

I have the following which is a simplified version of what I have:

function MyClass(a,b) {
  this.a = a;
  this.b = b;
}

MyClass.prototype.f1 = function(a) {
    this.a = a;
};

MyClass.prototype.f2 = function(a) {
    this.f1(a);
};

var mc1 = new MyClass(1,2);

Now I am getting an error saying:

this.f1 is undefined

If I move f1 out to its own function, there error is gone.

What could be causing this problem?
I know if you run the simplified version above it should work, but what could be causing the issue in my codebase? (I can’t post it here, but any hints on what to look for?)

Update

Ok after tracing it in firebug, it seems the keyword ‘this’ has been rebound somehow and it is no longer bound to the class MyClass, hovering over it is shows ‘function’.

What happened is that I set this function MyClass.f2 as a callback to Telerik editor, and it has somehow changed the scope of ‘this’.

What are my options to fix this?

  • 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-25T15:58:18+00:00Added an answer on May 25, 2026 at 3:58 pm

    One option is to refactor your code to a version that avoids using the prototype property:

    function MyClass(a, b) {
        var t = this;
    
        t.f1 = function(a) {
            t.a = a;
        };
    
        t.f2 = function(a) {
            t.f1(a);
        };
    
        // constructor code...
        t.a = a;
        t.b = b;
    }
    

    This way you have a persistent reference to the current instance that you can use instead of the this keyword.

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

Sidebar

Related Questions

I have a document which when simplified looks like this: <?xml version=1.0?> <document> <br/>
I have a code a following (simplified version): #define MESSAGE_SIZE_MAX 1024 #defined MESSAGE_COUNT_MAX 20
Consider the following simplified version of my code. I have a template class A
I have the following simplified XML structure: <?xml version="1.0" encoding="UTF-8"?> <ExportData> <TransportHeader> <Timestamp>2011-01-16 06:00:33</Timestamp>
I have the following table structure (simplified version) +----------------+ +-----------------+ +------+ | fee_definition |
I have the following two tables (simplified for this question): CREATE TABLE team (
I have the following which works in SQL Query Analyzer . select oh.* from
I'm trying to use opengl in C#. I have following code which fails with
I have following Code Block Which I tried to optimize in the Optimized section
I have the following interface which I'm trying to make COM-visible. When I try

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.