What is meant by 'first class object'?

后端 未结 11 1498
生来不讨喜
生来不讨喜 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:05

    The notion of "first-class functions" in a programming language was introduced by British computer scientist Christopher Strachey in the 1960s. The most famous formulation of this principle is probably in Structure and Interpretation of Computer Programs by Gerald Jay Sussman and Harry Abelson:

    • They may be named by variables.
    • They may be passed as arguments to procedures.
    • They may be returned as the results of procedures.
    • They may be included in data structures.

    Basically, it means that you can do with functions everything that you can do with all other elements in the programming language. So, in the case of JavaScript, it means that everything you can do with an Integer, a String, an Array or any other kind of Object, you can also do with functions.

提交回复
热议问题