Why does no exists method in p5.js?

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:

function method (codeToExecute){
    var tmpFunc = new Function(codeToExecute);
    tmpFunc();   
}
1 Like

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.

P5.js is open source on GitHub here.

1 Like

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

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

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

2 Likes

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

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

1 Like

thanks for info!
Regards

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

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

then to use it:

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