Terminology for various types of functions

JavaScript seems to have several different “groups” of functionally similar things. Here are my names for them:

  • "Regular functions": they are called using parsers and with new . Most features fall into this category.

  • "Functions only for the constructor": they can only be called with new . For example, Image , DOMParser , etc.

  • "Non-constructor functions": they are called using parsers, but not with new . For example, Math.round , Function.prototype .

  • Non-Callable Functions: These functions are not callable at all. For example, window.constructor , Document , NodeList , etc.

What are the name names for these different function groups?


I am also trying to find out if any of the "groups" of the function can be dependent on whether its [[Prototype]] ( __proto__ ) __proto__ to Function.prototype .

  • Most “ordinary functions” will have Function.prototype , but it can be removed using the non-standard __proto__ .

  • Most constructor-only functions have Object.prototype . I can not find cases where they have Function.prototype (like no call or apply ). This is always the case: / spec 'd behavior?

  • Non-constructor functions seem to basically have Function.prototype , with the exception of Function.prototype itself. Are there other cases that have Object.prototype ?

  • "Non-callable functions" always appear to be Object.prototype . Is this the case?


I will answer some answers here:

Regular Function: function
Constructor: constructor
Unconstructor: method
Non-callable: interface

This is not what I am looking for. "function" and "constructor", of course, are correct in general, but I'm looking for something more specific ("non-constructor function", etc.).

The "method" is no better than the "function", saying that it cannot be called with new , and the constructor does not get a point through which it can only be called with new .

In many cases, functions that cannot be called are available only from the constructor property of the host object. I think that most of them will more accurately be called "constructors" than "interfaces".


[Information about host objects and source objects]

This seems like the right way. Given this question (and the accepted answer and its comments), there seems to be some disagreement or confusion as to whether the user-defined functions are the host or native objects.

To avoid this, let’s just call UDF custom functions and not worry about whether they are the host or the native. So we have UDFs, host objects, and our own objects.

  • "Regular Functions"

    • Every UDF

    • Native objects like Object , String , etc.

    • Host objects such as window.toString (tested in Chrome 18).

  • "Functions for constructor only"

    • No own objects?

    • Host objects such as DOMParser , Image .

  • "Non-design functions"

    • Native objects such as Math.round and Function.prototype .

    • Host objects such as DOMParser#parseFromString .

  • "Not called functions"

    • No own objects?

    • Host objects such as NodeList , DocumentFragment .

So it seems like there is a relationship between host objects and constructor-only / no-call functions, but host vs native does not seem to apply to non-constructor and regular functions.

+7
source share
2 answers

I think that you are gaining nuances here between built-in objects built into EcmaScript and host objects created and provided by the developer.

The Regular Functions map for host objects, that is, functions created using JS and Constructor-Only Functions, Non-Constructor Functions, and Non-Called Functions, are mapped to native objects embedded in a lower level language.

http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf

+1
source

I don’t think there is an official name for what you are asking for, but usually people call all these functions in any programming language:

  • Regular Function: function
  • Constructor: constructor
  • Unconstructor: method
  • Non-callable: interface (in the case of JS, this applies to native objects at a lower level)
0
source

All Articles