Provide compiler warnings/errors when using method as callback and this
context won't be preserved
#26881
Closed
4 tasks done
Labels
Duplicate
An existing issue was already created
Search Terms
bind, this, callback
Suggestion
Emit a warning or error when a method meets these conditions:
this
context to be preserved (uses thethis
keyword).Use Cases
The standard syntax for defining methods is clean, concise, familiar, and (arguably) preferable to everyone. However, methods defined using this common syntax will not preserve the context of
this
when passed as a callback to another function. This mistake is easy to make, yet perfectly legal!Examples
Using the above example, I'd love to see the compiler offer the suggestions made in this page. Something like this
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: