Ashish Kumar

Jan 04, 2026 • 2 min read

Javascript and objects - 2

Understand objects in depth in javascript

Please read the first part of this here before continuing.

We talked about arrays as objects in the first part , but in javascript except for primitives everything is an object.

So does that mean if we create a set or any function we can hope for it to work like an object ? Yes , although this sounds ambiguous but yes it can be done.

The same thing can be done with functions , but why is like that ? Why it happens , is it on purpose ?

Yes it is on purpose , the creator wanted to combine OOPS programming and functional programming into one.

And it is actually good , since you have this power in functions you can do a bunch of things using functions directly , for eg:

  1. memoization .You can directly store values into the functions and later use them as required in a recursion scenario or to use DP alike approach .

this helps you to store these values directly inside the function itself

  1. closures : function being able to remember what its last value was , have a look at the below code snippet

    counterCreator is the first counter , and look how anotherCounterCreator is a different counter , both are different and different instances of it , help create different counters , while remembering the last value .

Therefore anything that can be done with any object can be done with the functions , so let me give you another example to exaggerate on this very thing.

In this example even though only wizard has the heal function but using call method we can change the environment to change this and environment for that function to archer's .

Finally you can use it as an object as well , similar to how you would do in class-es , but by not using classes of course.

Summary

Functions are objects and a few achievable things due to this property are :

  1. closures

  2. memoization

  3. changing environment (using call , bind and apply)

  4. Blueprint


I hope you liked the above article , if you did or didnot please comment stating my mistakes.

Join Ashish on Peerlist!

Join amazing folks like Ashish and thousands of other builders on Peerlist.

peerlist.io/

It’s available... this username is available! 😃

Claim your username before it's too late!

This username is already taken, you’re a little late.😐

2

5

0