You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/09-classes/02-class-inheritance/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -236,11 +236,11 @@ The short answer is: constructors in inheriting classes must call `super(...)`,
236
236
237
237
Of course, there's an explanation. Let's get into details, so you'll really understand what's going on.
238
238
239
-
In JavaScript, there's a distinction between a "derived constructor" (constructor function of an inheriting class) and other functions. A derived constructor has a special internal property `[[ConstructorKind]]:"derived"`. In other words, the constructor function of a class that "extends" something bears a "special label".
239
+
In JavaScript, there's a distinction between a constructorfunction of an inheriting class (so-called "derived constructor") and other functions. A derived constructor has a special internal property `[[ConstructorKind]]:"derived"`. That's a special internal label.
240
240
241
241
That label affects its behavior with `new`.
242
242
243
-
- When a regular function `F`is executed as`new F`, it creates an empty object and assigns it to `this`.
243
+
- When a regular function is executed with`new`, it creates an empty object and assigns it to `this`.
244
244
- But when a derived constructor runs, it doesn't do this. It expects the parent constructor to do this job.
245
245
246
246
So a derived constructor must call `super` in order to execute its parent (non-derived) constructor, otherwise the object for `this` won't be created. And we'll get an error.
0 commit comments