# Cannot use method as lambda; did you forget '()'?

**URL:** <https://forum.makecode.com/t/cannot-use-method-as-lambda-did-you-forget/4310>\
**Category:** micro:bit\
**Created:** [November 6, 2020, 6:16pm UTC](https://forum.makecode.com/t/cannot-use-method-as-lambda-did-you-forget/4310 "2020-11-06T18:16:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshkeys19](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/joshkeys19/32/2182_2.png) [@joshkeys19](https://forum.makecode.com/u/joshkeys19)\
**Post date:** [November 6, 2020, 6:16pm UTC](https://forum.makecode.com/t/cannot-use-method-as-lambda-did-you-forget/4310/1 "2020-11-06T18:16:12Z")

</div>

Hi everyone.

I’m wondering if someone could help me with the error:

**cannot use method as lambda; did you forget ‘()’ ?**

I’ve made a very simplistic replication of my error here below. It is when I call this.foo. Any help appreciated!

Thanks,  
Josh

`
 class fibFooClass 
    {
        foo()
        {
```
    }

    fib()
    {
        fibfoo(this.foo)
    }
}

function fibfoo(callback:()=>void)
{

//Do stuff with callback function

}

```
` Or if you prefer a picture:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/7/74e7d8872c39e4cc6613bdb7e169fb85c5515721.png)

---

<div class="post-metadata">

**Author:** ![joshkeys19](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/joshkeys19/32/2182_2.png) [@joshkeys19](https://forum.makecode.com/u/joshkeys19)\
**Post date:** [November 6, 2020, 9:43pm UTC](https://forum.makecode.com/t/cannot-use-method-as-lambda-did-you-forget/4310/2 "2020-11-06T21:43:44Z")

</div>

Hi everyone.

I was able to solve this by doing the following:

fibfoo(this.foo) I changed to:

fibfoo(()=\>this.foo)

I’d love it if someone could explain this a bit. I somewhat get why, but not entirely. 🙂

Thanks,  
Josh

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [November 6, 2020, 10:18pm UTC](https://forum.makecode.com/t/cannot-use-method-as-lambda-did-you-forget/4310/3 "2020-11-06T22:18:10Z")

</div>

MakeCode does not support passing methods as functions (we deviate from the JavaScript specification). I think what you actually want is:

```auto
fibfoo(() => this.foo())

```

---

<div class="post-metadata">

**Author:** ![joshkeys19](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/joshkeys19/32/2182_2.png) [@joshkeys19](https://forum.makecode.com/u/joshkeys19)\
**Post date:** [November 6, 2020, 10:23pm UTC](https://forum.makecode.com/t/cannot-use-method-as-lambda-did-you-forget/4310/4 "2020-11-06T22:23:59Z")

</div>

Hi Richard,

Yes, I was able to fix it with that as I mentioned above. Are you able to explain this a bit further? When doing it with just “this.foo” I assume passing the method messes things up as it is an instance of a class method. Does using the anonymous function to copy the class method remove the “instance” of it?

Thanks,  
Josh

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [November 6, 2020, 10:28pm UTC](https://forum.makecode.com/t/cannot-use-method-as-lambda-did-you-forget/4310/5 "2020-11-06T22:28:49Z")

</div>

When you use the anonymous function, you are passing a function that calls the method on the instance of the class instead of the method itself. The reason that you can’t pass the method directly is because of how we generate code; methods are emitted differently than functions (we use vtables).

---

<div class="post-metadata">

**Author:** ![joshkeys19](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/joshkeys19/32/2182_2.png) [@joshkeys19](https://forum.makecode.com/u/joshkeys19)\
**Post date:** [November 9, 2020, 4:21pm UTC](https://forum.makecode.com/t/cannot-use-method-as-lambda-did-you-forget/4310/6 "2020-11-09T16:21:40Z")

</div>

Hi Richard,

Thanks for the explanation! Much appreciated!

Thanks,  
Josh
