0

What do you call an object with a function in it. I'm documenting some functions that return this with jsdoc and I'm having trouble sticking with one way of conveying this.

This is what I'm returning

{fnName: [function]}

or

{fnNameA: [function], fnNameB: [function]}

My problem documenting the return value this way is conveying not to expect property as literal object.fnName and as a variable function name.

How do I represent this in jsdocs? Is the above the standard?

What do we as programmers call this kind of variable?

  • Object where values are functions
  • Object with functions
  • Object with function properties
  • Object with methods
  • Object with named function properties

Is there one word that conveys this?

ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
  • The best, succinct word I can think of is "API", but that is of course still generic. – light Jul 25 '15 at 04:52
  • @light: API only truly applies if it is a programming interface, and somewhat exposed to code consumers. – Fuzzical Logic Jul 25 '15 at 04:54
  • If it's a library you're building (an object exporting a collection of functions), I think this can qualify as an API. But really, I don't think there's any technical word to describe what the OP is asking for. The word to describe such an object is more or less bound to the context of the application. – light Jul 25 '15 at 05:22
  • Balthazar...or Alan – Fraser May 24 '17 at 14:11

2 Answers2

4

The proper programming answer is Object with methods. This is because the property's value is a function, whether named or not. But it should be understood that a method is simply a property that is a function. The reason we distinguish them is that interacting with them properly requires a slightly different signature, resulting in an invocation. However, it should be noted that other terms might apply depending upon usage and accessibility. For instance, if the object is to be used by a code consumer, API might also apply.

An important clarification:

They are only named functions if the function has a name (a property name is not a function name). For example, the below would be a named function:

{
    prop1: function myFn() {
    }
}
Fuzzical Logic
  • 12,947
  • 2
  • 30
  • 58
  • Thanks for the clarification part. That's a great distinction. – ThomasReggi Jul 25 '15 at 04:59
  • Could we call it `Method Object` for brevity? Would that be widely understood? – ThomasReggi Jul 25 '15 at 05:01
  • 1
    No. There's no such thing... A Method is a property of an Object... so it would not make sense to try and create such a distinction, especially if you are attempting to use this for documentation. Simply Object... and it has the following methods: a, b, and c. – Fuzzical Logic Jul 25 '15 at 05:04
  • 1
    That said, the only reason there is not such a distinction is because in JavaScript, your properties may change their types at a whim... since there is no hard-typing, every code pattern is essentially a convention. – Fuzzical Logic Jul 25 '15 at 05:06
0

I never seen special distinction for "object that only have properties with functions as values".

I'd use: "Object with properties" or maybe "object with methods" (as I'm from more strongly typed world).

If result normally used as argument of another function - "options object" (as in options JavaScript pattern ).

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179