Previously, we have talked about all things being an object in Javascript. But to what extent can we apply this to our beloved functions.
You can see this almost everywhere with the below syntax -
|
|
We have also touched upon how function is an object and how that helps in using closures and currying.
For now, let’s leave all those complex things behind. Function being an object implies that we can do this -
|
|
We just define a function like we define an object, and pass variables and function body as parameters to the constructor.
You get the function
object as output from a type of
.
|
|
However, you would also know that every object functions with a function
in the form of a constructor.
|
|
Therefore, anything without a function is just so primitive (a silly joke and a fact(?)).