Professional Documents
Culture Documents
Document 19
Document 19
Although classes are now widely adopted and have become a new paradigm in
JavaScript, classes do not bring a new inheritance pattern. While classes abstract most of
the prototypal mechanism away, understanding how prototypes work under the hood is
still useful.
Inheriting properties
There are several ways to specify the [[Prototype]] of an object, which are listed in a
later section. For now, we will use the __proto__ syntax for illustration. It's worth noting
that the { __proto__: ... } syntax is different from the obj.__proto__ accessor:
the former is standard and not deprecated.
JSCopy to Clipboard
const o = {
a: 1,
b: 2,
// __proto__ sets the [[Prototype]]. It's specified here
// as another object literal.
__proto__: {
b: 3,
c: 4,
},
};