, and, obviously, the so-called
— there are primitives, but they're converted to anobject when you need to operate upon them. An object in the language is simply a collection of key/valuepairs (and some internal magic sometimes).There are no concepts of classes anywhere, though. That is, an object with properties
name: Linda,age: 21
is not an instance of any class, the
are instances of themselves. They define their own behaviour, directly. There are no layers of meta-data (i.e.: classes) todictate what given object must look like.You might ask: "how?"; more so if you come from a highly classically Object Orientated language (like Java orC#). "Wouldn't having each object defining their own behaviour, instead of a common
mean that if Ihave 100 objects, I will have 100 different methods? Also, isn't it dangerous? How would one know if an objectis really an Array, for example?"Well, to answer all those questions, we'll first need to unlearn everything about the classical OO approach andstart from the ground up. But, trust me, it's worth it.The prototypical OO model brings in some new ways of solving old problems, in an more dynamic andexpressive way. It also presents new and more powerful models for extensibility and code-reuse, which iswhat most people are interested about when they talk about Object Orientation. It does not, however, giveyou contracts. Thus, there are no static guarantees that an object
will always have a given set of properties,but to understand the trade-offs here, we'll need to know what we're talking about first.