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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:59:37+00:00 2026-06-16T03:59:37+00:00

In typescript, I can write something like this: $(‘#something’).fadeOut(400, (): void => { this.invokeAnotherMethod();

  • 0

In typescript, I can write something like this:

$('#something').fadeOut(400, (): void => {
    this.invokeAnotherMethod();
});

When compiled, TypeScript automatically makes sure this points to my class instead of the enclosed function:

var _this = this;
$('#something').fadeOut(400, function() {
    _this.invokeAnotherMethod();
});

However, what about when I need to access the real this instead of the outer _this? Is there syntax to reference it? For example, how could I write code that would compile to the following:

var _this = this;
$('#something').fadeOut(400, function() {
    $(this).data('specialhide', true);
    _this.invokeAnotherMethod();
});

Is it possible?

  • 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-16T03:59:39+00:00Added an answer on June 16, 2026 at 3:59 am

    You would need to avoid the fat-arrow syntax to do this as you don’t want to preserve the lexical scope of this.

    var _me = this;
    $('#something').fadeOut(400, function () {
        _me.invokeAnotherMethod();
        $(this).data('specialhide', true);
    });
    

    In this example I have used _me rather than _this to avoid any collisions with TypeScript generated variables. I have also avoided self, to avoid confusion with window.self (thanks RockResolve).

    The Why!

    The ECMAScript 6 specification features Arrow Function Definitions – it is where the TypeScript language has taken this feature from. When TypeScript targets ECMAScript 6 in the future, it will leave in the () => syntax – so they can’t make it work with both contexts of this without breaking future compatibility.

    Even though you could imagine how they could change the TypeScript compiler to make both _this and this available in ECMAScript 3 or 5, it would actually become a problem in version 6.

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

Sidebar

Related Questions

Looks like TypeScript has a nice module system, however does this replace the need
Can someone explain how would this look in TypeScript. Can it be done via
I'd like to use TypeScript to declare functions with parameters that can be either
The script utility works like this: $ script Script started, file is typescript $
UPDATE TypeScript 1.5.3 added declarations for HTML Touch events to lib.d.ts I can see
I have a node app that has a string of require s, like this:
I can't seem to figure this one out. I have a validator-type script that
I am building a Backbone app in TypeScript and I would like to put
I have a test project on TypeScript, code can found here . When I'm
If I'm working in a TypeScript .ts file, what can I do to get

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.