---

Class-less Objects in JavaScript

[ Thanks to Bhushan
Pangaonkar
for this link. ]

“So which way is better – object literal or constructor
function? Well, that depends on your specific task. For example, if
you need to create many different, yet similar objects, then the
class-like constructors may be the right choice. But if your object
is more of a one-off singleton, then object literal is definitely
simpler and shorter.

“OK then, so since there are no classes, how about inheritance?
Before we get there, here comes a little surprise – in JavaScript,
functions are actually objects.”

Complete
Story

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis