Object's properties.

edited July 2016 in p5.js

Hello, Where or how can I access the properties (methods) that can be passed to an object? For example, if I want to know which properties I can pass to the ellipse() object, where can I find this information? I am having a hard time finding out how to talk to my objects.

At the moment I am using console.dir(Object.keys(ellipse())); but what I cannot really make sense of what it is returning.

Any help is welcome. Apologies if the question has been asked before, I could not find the answer in the forum.

Thanks! Irving.

Answers

  • Answer ✓

    In theory you should find all the information you need in the p5js reference. For example here's the entry for ellipse.

    There's an obvious problem with using console.dir(Object.keys(ellipse())); to inspect Ellipse's (or any Object's) composition: it also includes inherited properties. If you look at the source you'll see that Ellipse exposes NO public properties/methods whatsoever... Note also that preceding an identifier with an _underscore is a convention for private properties/methods that you should avoid depending on in your code: and that's the case for the majority of Ellipse's inherited properties/methods...

  • edited July 2016 Answer ✓

    ... if I want to know which properties I can pass to the ellipse() object, where can I find this information?

    Look up its reference: http://p5js.org/reference/#/p5/ellipse

    Some jargon explanation though: :-B

    • ellipse()'s more correct term is function, even though functions are objects too.
    • We don't pass properties but arguments to functions. Which in turn are assigned to their corresponding parameters.
    • Functions in JS don't have formal signatures for their parameters and return types like we have in Java or C.
    • We can pass as many arguments of any types and expect 1 returning value of any type.
    • We can check a function's length property in order to know how many parameters were declared.
    • However, given that JS doesn't force us to stick w/ that quantity, the actual number of parameters can vary depending on the internal implementation of each function.
  • Thank you, both, for your answers.

    I apologize if I did not explain my question clearly. I am well aware of the reference page. The reason why I ask the question is because it seems to me that it lacks essential information as to which methods to pass the objects.

    Regardless, it seems I was a bit confused, or just ignorant about the library.

    It makes a lot of sense that ellipse() is a function, even if still an object. My guess is that I will need to create an object that holds the function.

    Thanks again, your answers are very helpful.

  • Answer ✓

    It makes a lot of sense that ellipse() is a function, even if still an object.

    Gonna try to be more pedantic precise. Hope it doesn't make things messier to understand. ^#(^

    • ellipse is itself a property of p5's prototype object.
    • But b/c it is assigned to a function "object", we call it the ellipse() function.
    • All functions & arrays are objects in JS. And if we look deeper, even numbers, boolean, strings, undefined, etc. are as well. @-)
  • Hahaha, well, thank you. I do understand the concepts to a good level. It is helpful for me to see the source code and try to get the hang of it, even though I am not too familiarized with JS and the p5js libraries.

    Thanks again for your time, I appreciate it!

Sign In or Register to comment.