# Why does no exists method in p5.js?

**URL:** https://discourse.processing.org/t/why-does-no-exists-method-in-p5-js/1013
**Category:** p5.js
**Created:** [June 16, 2018, 4:09pm UTC](https://discourse.processing.org/t/why-does-no-exists-method-in-p5-js/1013 "2018-06-16T16:09:06Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![erkosone](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@erkosone](https://discourse.processing.org/u/erkosone)
#### Post date: [June 16, 2018, 4:09pm UTC](https://discourse.processing.org/t/why-does-no-exists-method-in-p5-js/1013/1 "2018-06-16T16:09:06Z")

</div>

Why does not the method () function exist in p5.js? It is simple to implement. p5.js will be expanded with more functions as it has processing in java mode? Where can I find out about the development status of p5.js?

ex:

```auto
function method (codeToExecute){
    var tmpFunc = new Function(codeToExecute);
    tmpFunc();   
}

```

---

<div class="post-metadata">

### Author: ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)
#### Post date: [June 16, 2018, 4:19pm UTC](https://discourse.processing.org/t/why-does-no-exists-method-in-p5-js/1013/2 "2018-06-16T16:19:03Z")

</div>

I don’t really understand what this function is doing. Can’t you just call `codeToExecute` directly? In any case, this function could really be shortened to one line of code:

```
new Function(codeToExecute)();

```

Again, I don’t really see what this is doing, but my point is that you wouldn’t really need this to be a P5.js function, since you can already do it in one line anyway.

> [@erkosone](#):
>
> Where can I find out about the development status of p5.js?

P5.js is open source on GitHub [here](https://github.com/processing/p5.js).

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [June 16, 2018, 4:50pm UTC](https://discourse.processing.org/t/why-does-no-exists-method-in-p5-js/1013/3 "2018-06-16T16:50:07Z")

</div>

If you present a short code sample in Java that shows what you would like to do and what you would like to port to js, you will probly get more suggestions.

Kf

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [June 16, 2018, 9:30pm UTC](https://discourse.processing.org/t/why-does-no-exists-method-in-p5-js/1013/4 "2018-06-16T21:30:21Z")

</div>

```auto
p5.prototype.method = function (m) {
  this[m]();
  return this;
};

```

---

<div class="post-metadata">

### Author: ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)
#### Post date: [June 16, 2018, 9:32pm UTC](https://discourse.processing.org/t/why-does-no-exists-method-in-p5-js/1013/5 "2018-06-16T21:32:34Z")

</div>

@GoToLoop Can you please explain the code you just posted? What does it do? How does it help solve OP’s problem?

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [June 16, 2018, 9:36pm UTC](https://discourse.processing.org/t/why-does-no-exists-method-in-p5-js/1013/6 "2018-06-16T21:36:09Z")

</div>

> [@Kevin](#):
>
> How does it help solve OP’s problem?

Let’s w8 for @erkosone for it, then I’ll clarify it more. 😼

After all, it follows the same approach I’ve already done for him here: 🙄

> [@How i extends class in p5.js?](https://discourse.processing.org/t/how-i-extends-class-in-p5-js/894/3):
>
> JavaScript got a prototype inheritance system, in which we make available all properties to be extended by annexing them all to a constructor function’s property object {} called prototype: card_file_box For example If we wanna extend the class p5 (classes are constructor functions btW) w/ a new method called square(), we can simply annex it to p5.prototype{} object, like this: +1 p5.prototype.square = function (x, y, size) { return this.rect(x, y, size, size); }; And a more complex…

---

<div class="post-metadata">

### Author: ![erkosone](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@erkosone](https://discourse.processing.org/u/erkosone)
#### Post date: [June 17, 2018, 7:26am UTC](https://discourse.processing.org/t/why-does-no-exists-method-in-p5-js/1013/7 "2018-06-17T07:26:30Z")

</div>

thanks for info!  
Regards

---

<div class="post-metadata">

### Author: ![codingking03](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@codingking03](https://discourse.processing.org/u/codingking03)
#### Post date: [June 17, 2018, 11:05am UTC](https://discourse.processing.org/t/why-does-no-exists-method-in-p5-js/1013/8 "2018-06-17T11:05:24Z")

</div>

This is kinda strict in how you format it but I always use an object as the argument and the function as part of the object

```auto
function method (obj){
var tmpFunc = obj.codeToExecute //this is very important once you chose you cant change it
tmpFunc();
};

```

then to use it:

```auto
method( { codeToExecute: function(){
/// code goes here
},
 } );

```
