What is meant by 'first class object'?

后端 未结 11 1538
生来不讨喜
生来不讨喜 2020-11-22 10:46

In a recent question, I received suggestions to talk on, amongst other things, the aspect of JavaScript where functions are \'first class\' objects. What does the \'first c

11条回答
  •  一向
    一向 (楼主)
    2020-11-22 11:02

    Definition on the Mozilla site is concise and clear. According to them,

    In JavaScript, functions are first-class objects, because they can have properties and methods just like any other object. What distinguishes them from other objects is that functions can be called. In brief, they are Function objects.

    And

    a function is a "subprogram" that can be called by code external (or internal in the case of recursion) to the function. Like the program itself, a function is composed of a sequence of statements called the function body. Values can be passed to a function, and the function will return a value.

提交回复
热议问题