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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:10:41+00:00 2026-06-12T13:10:41+00:00

I have a function defined in a object like this: connect(callback?: (connected: bool) =>

  • 0

I have a function defined in a object like this:

    connect(callback?: (connected: bool) => void) {
        $.ajax(this.url + "/connect", $.extend(true, {}, this.ajaxSettings, {
            success: (data) => {
                this.errorChecker(data, (data) => {
                    if (callback != null) {
                        callback(data);
                    }
                });
            },
            timeout: this.timeout,
            error: () => {
                if (callback != null) {
                    callback(false);
                }
            }
        }));
    }

The TypeScript compiler takes that and produces this:

        VAS.prototype.connect = function (callback) {
            $.ajax(this.url + "/connect", $.extend(true, {
            }, this.ajaxSettings, {
                success: function (data) {
                    _this.errorChecker(data, function (data) {
                        if(callback != null) {
                            callback(data);
                        }
                    });
                },
                timeout: this.timeout,
                error: function () {
                    if(callback != null) {
                        callback(false);
                    }
                }
            }));
        };

Note this line in the js:

_this.errorChecker(data, function (data)

The compiler has correctly noticed my use of the => operator and concluded that this in my original TypeScript should refer to the parent object and not whatever this happens to be when the success callback is actually called. But, for some reason the compiler has forgotten to include the magic line:

var _this = this;

At the start of the function. Is this a bug? Or is this by design? If it just ignored the _this / this thing altogether, I’d just say I’m doing it wrong, but it’s going half way here which makes me think something is wrong.

Update: oddly this seems to be a problem with the compiler in Visual Studio, if I copy the same code into the playground it works as expected.

  • 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-12T13:10:42+00:00Added an answer on June 12, 2026 at 1:10 pm

    This looks like a bug. You should open a work item to track this.

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

Sidebar

Related Questions

I have a function defined like this: public static void ShowAbout(Point location, bool stripSystemAssemblies
I have javascript object defined like this: function SocialMiner() { var verbose=true; var profileArray=new
Suppose I have a function defined like this: class Foo() { public: void bar(MyClass*
I have an object defined like this: Blah = { hideTimer:null, setTimer: function() {
If I have a javascript object/assoc. array defined like this: function somefunction(options) { var
I have the following object defined function BusinessUnit(id, name, code) { this.id = ko.observable(id);
In an ASP.MVC application, I have a function defined in my _ViewStart.cshtml like this:
I have a function like this defined in one class: using System; using System.Collections.Generic;
I have an object called ValueBox that I created like this: function ValueBox(params) {
Let us presume I have the following object defined: var myObj = function(){ this.hello

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.