What do you call an object with function(s) in it

≯℡__Kan透↙ 提交于 2019-12-13 07:41:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!