DEV Community

Discussion on: I Don't Use JavaScript Classes At All. Am I Missing Out on Something?

Collapse
 
andi23rosca profile image
Andi Rosca

“classes are a poor mans clojure” I think it’s from the tao of programming book. But i agree with it in case of JS, since it doesn’t have classes in the same way C# or Java do, you can just use closures when you need to keep state and have functions work on it.

Collapse
 
sebring profile image
J. G. Sebring

I recall it goes

"objects are merely a poor man's closures"

but the key point to the statement is it can be reversed, hence

"closures merely a poor man's object"

Collapse
 
andi23rosca profile image
Andi Rosca

Yeah true. In some ways objects can be considered better since they have more functionality attached to them, but in JS to me at least they’re pretty much the same thing.

I prefer closures since JS doesn’t have private properties on classes but you can choose not to return things from a closure and keep them private in a sense.