First-class function in JavaScript and Java
What is first-class function?
- Can be named by variables.
- Can be passed as arguments to procedures.
- Can be returned as the results of procedures.
- Can be included in data structures.
Functions are first class objects in JavaScript
With reference from this post,
functions are first class objects in JavaScript:
- A function is an instance of the Object type
- A function can have properties and has a link back to its constructor method
- You can store the function in a variable
- You can pass the function as a parameter to another function
- You can return the function from a function
First class objects in Java
In Java these are first class objects:
- Primitive values: int, double, long, short, byte, char…
- Objects: new Integer(1), new ArrayList(), new Person()…
Classes and methods are second class objects…until when Java 8 was introduced:
We will try to pass a function as parameter to other function