问题
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?
回答1:
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() {
}
}
回答2:
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 ).
来源:https://stackoverflow.com/questions/31623026/what-do-you-call-an-object-with-functions-in-it