What is meant by 'first class object'?

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

    Simple test. If you can do this in your language (Python as example):

    def double(x):
        return x*x
    
    f = double
    
    print f(5) #prints 25
    

    Your language is treating functions as first class objects.

提交回复
热议问题