1,278 questions
1
vote
2
answers
57
views
ES6 static class extends EventTarget
I wish to create a class which extends EventTarget, allowing addEventListener() and dispatchEvent() to be invoked on it.
Logically, my class wants to be a singleton; if a page accidentally ...
1
vote
0
answers
42
views
Inheriting constructor documentation in JSDoc with ES6 classes
I am writing documentation for some classes written using the ES6 class syntax. I have some classes which inherit their constructor from their parent class, as below:
/**
* @class
*/
class Parent {
...
1
vote
1
answer
39
views
Why do private fields not get overridden in subclasses?
I'm trying to create a parent class A with a private field #abc and a subclass B that overrides this field. However, when I call methods from the parent class that access the private field, it still ...
0
votes
2
answers
120
views
How do I see my private class field values in Firefox debugger?
When the code pauses at a breakpoint, where in devTools are my private class variables displayed? I can see the public ones but not the privates (I mean variables prefixed with #)
class MyClass {
...
1
vote
0
answers
41
views
Why can't I set a private field in a function called from a superclass constructor? [duplicate]
When I run the following code in Node.js:
class Superclass {
constructor() {
this.setPrivateField();
}
setPrivateField() {
// No implementation
}
}
class Subclass extends Superclass {...
0
votes
1
answer
53
views
Why is inheritance using constructor functions "hard to do properly" (MDN)?
The MDN's article for "Inheritance and the prototype chain", under "Different ways of creating and mutating prototype chains": "With constructor functions", gives the ...
1
vote
1
answer
351
views
JavaScript class with static methods vs object with function properties
In JavaScript (and TypeScript) is there any difference between using a class vs an object to namespace methods from a performance perspective? And are there any other reasons to prefer one option over ...
0
votes
1
answer
49
views
Get value of private variable in extension method ES6 class in JavaScript
I have a JavaScript ES6 class in a library that uses some private base values to compute another value.
Abstracted and simplified the situation is something like this:
class Example {
#apples;
#...
-1
votes
1
answer
77
views
Detect direct instances in JavaScript
A couple of years ago, I wanted figure how to create a type check for class A that returns true only for objects instantiated by new A(). For this, I wrote the class like this:
class A {
static #...
-2
votes
2
answers
111
views
How to correctly implement a 'Child' class that extends a 'Parent' class and inherits a class field from the latter?
This is my task
Implement a Child class that extends the Parent.
Add a constructor to the Child class can calls super().
Implement a new function addNewAbilities(newAbility) in the Child class where ...
1
vote
2
answers
113
views
Change prototype chain in multiple level class inheritance
Since JS doesn't allow to extends more than one class, we could be with a complex inheritance chain like this
class Level1 {
constructor() {
this.level = 1;
}
method1() {
...
0
votes
1
answer
92
views
Extending a JavaScript ES6+ class that explicitly returns an object in its constructor
I'm having issue with extending a Javascript ES6+ class that returns an object from the constructor.
Take for example:
class Base {
constructor() {
return {name: "base"}
}
}
class ...
0
votes
0
answers
98
views
Sequelize Models, registered, synced, but how to do CRUD-Operations?
i used a course on udemy to make my first steps with sequelize: https://github.com/DavidArmendariz/sequelize-course/tree/master
Because I only want to use ES-Modules I had to make a few adjustments.
...
0
votes
1
answer
111
views
ES6 classes extends a class with returning constructor
In the following code I have an unexpected behaviour for me. I was waited to see the method A2::method() to be called, but it is A0::method() instead.
More tests showed me that if A1 returns something,...
0
votes
2
answers
117
views
verbose class definition in TypeScript
I have a class with a destructured constructor parameter:
import * as ē from 'three'
export class cylindricCurve extends ē.Curve {
#scale: number
#eqs: ((θ: number) => number)[]
#rounds: ...