Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No warning when you use 'this' inside a function #2770

Closed
wizofaus opened this issue Apr 15, 2015 · 2 comments
Closed

No warning when you use 'this' inside a function #2770

wizofaus opened this issue Apr 15, 2015 · 2 comments
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead

Comments

@wizofaus
Copy link

If my class consists of

class X {
  foo() {
  }
  bar() {
     setTimeout(function() {
        this.foo();
     }, 10)
  }
}

I really should get some sort of warning that "this" doesn't mean what I think it means (or that I should use lambda syntax). This has bitten me repeatedly as I've been converting js code into ts code.

@wizofaus
Copy link
Author

(I seen noticed #1985, but I've put a comment as to why this isn't quite enough).

@RyanCavanaugh RyanCavanaugh added the By Design Deprecated - use "Working as Intended" or "Design Limitation" instead label Apr 15, 2015
@RyanCavanaugh
Copy link
Member

The behavior as-is is by design, as sometimes you really do need the this that isn't the lexical one. We're tracking the general problem in hope of solution in the referenced issue and others; no need for a separate one here.

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead
Projects
None yet
Development

No branches or pull requests

2 participants