# Callback function arguments

**URL:** <https://discourse.processing.org/t/callback-function-arguments/37588>\
**Category:** Beginners\
**Created:** [June 17, 2022, 12:17am UTC](https://discourse.processing.org/t/callback-function-arguments/37588 "2022-06-17T00:17:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidhurwich](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/davidhurwich/32/9458_2.png) [@davidhurwich](https://discourse.processing.org/u/davidhurwich)\
**Post date:** [June 17, 2022, 12:17am UTC](https://discourse.processing.org/t/callback-function-arguments/37588/1 "2022-06-17T00:17:55Z")

</div>

Hi, question about attaching event callback functions to an object in P5. Can those callback functions take arguments? for instance could I do something like this:

obj.mousePressed( function(argument));

?

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 17, 2022, 5:59am UTC](https://discourse.processing.org/t/callback-function-arguments/37588/2 "2022-06-17T05:59:17Z")

</div>

Hi,

No, not that way you probably think about.  
You should imagine, that the object calls your function on mousePressed event, and how the object should know, which argument it should use !?

But you can handle the cases inside the function ie.

```auto
obj.mousePressed(() => { 
  // calling foo with the required arg(s)
  foo(this.bar);
});

// ...

function foo(arg) { 
    // if (arg === whateverthis ) {
    // do whatever this
    // else {
    // do whatever that
    // }
} 

```

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![davidhurwich](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/davidhurwich/32/9458_2.png) [@davidhurwich](https://discourse.processing.org/u/davidhurwich)\
**Post date:** [June 17, 2022, 8:00pm UTC](https://discourse.processing.org/t/callback-function-arguments/37588/3 "2022-06-17T20:00:56Z")

</div>

> [@mnse](#):
>
> `() =>`

thanks for the response!
