6. Legacy and prototypes
JavaScript is a prototype-based language, which means it provides
objects but, natively, no classes. The difference between prototype-based
languages and class-based languages lies in the mechanism used to
create objects. In class-based languages, all objects of the same
class have the same structure (the same fields) and the same behaviors
(methods). In prototype-based languages, objects are created by cloning.
A clone initially acquires all the properties and behaviors of the
parent object (in JavaScript, this is called a prototype). It can
evolve independently of its prototype and dynamically acquire (or
lose) new behaviors or properties.
We will first present the prototypes, a concept on which ECMAScript
2015 has built a class system associated with new syntaxes for their
declaration.
Every object (including tables, functions, regular...
You do not have access to this resource.
Exclusive to subscribers. 97% yet to be discovered!
Already subscribed?
Log in!
Ongoing reading
Legacy and prototypes