• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: What happens when using ‘this’ inside a lambda expression that is sent to let function?

Resolved: What happens when using ‘this’ inside a lambda expression that is sent to let function?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I’ve looked at the source code of let function:
i clearly understand that using it keyword inside of the block (code) i’m sending to let function will refer to the object that called the let function. But on which object does this keyword will refer if i will use it inside the block (code). The way i see it, it should be the same object that it refer to, but i’m not sure. My computer gone bad so i can’t test it by myself. Can someone not only give me the answer but also will explain me the logic behind the this keyword in the situation above?
example of code:

Answer:

this in the let lambda (block) means the same thing as it does outside the let lambda. The let lambda does not suddenly “change” what this means.
For example:
This is because this refers to the receiver of a function, but the function type of the parameter that let takes has no receiver:
Compare that to run, which is very similar to let, except its receiver as the receiver of the block parameter:
which means that:
Another example that uses both this and it:
If you call usesBoth with a lambda,
this in the lambda would refer to 1, because block is called on x in usesBoth, and it would refer to “x”, because y is passed to block as a parameter.

If you have better answer, please add a comment about this, thank you!

kotlin lambda let
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Shopware 400 Status Error “This value is too long. It should have 255 character or less.” When I Try Updating Database Table

01/04/2023

Resolved: Using AWK to count multiple patterns in a file

01/04/2023

Resolved: significance letter above bar graphic in wrong order

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.