Skip to main content

Questions tagged [es6-class]

This tag is for questions regarding Classes in Ecmascript 6. The tag is only for classes provided in the Ecmascript version.

es6-class
0 votes
1 answer
34 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 ...
Aayla Secura's user avatar
1 vote
1 answer
67 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 ...
Cam Parry's user avatar
  • 116
0 votes
1 answer
32 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; #...
tesmo's user avatar
  • 155
0 votes
1 answer
65 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 #...
Melab's user avatar
  • 2,704
-2 votes
3 answers
85 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 ...
programmingnoob's user avatar
1 vote
2 answers
87 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() { ...
DaniloMourelle's user avatar
0 votes
1 answer
80 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 ...
calebpitan's user avatar
0 votes
0 answers
54 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. ...
Daniel Hüpenbecker's user avatar
0 votes
1 answer
81 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,...
Guile's user avatar
  • 1,484
0 votes
2 answers
78 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: ...
punund's user avatar
  • 4,371
1 vote
2 answers
301 views

How to extend Array to enforce specific arguments in TypeScript?

I'm using TypeScript and I want to extend Array to enforce a specific argument. This way, I can make sure that whenever I create a FruitArray, the first element is a fruit. So I tried extending Array ...
Patrick Kenny's user avatar
0 votes
2 answers
55 views

Why I can't use 'super' in prototype method definition when I can use Object.getPrototypeOf(this.constructor.prototype)?

So I tested this code: class C1 {} C1.prototype. f =function(){ return 1 } class C2 extends C1 {} C2.prototype. f =function(){ return super.f()+1 } And it throws a syntax error: 'super' keyword ...
user1533299's user avatar
0 votes
2 answers
133 views

Is it possible to modify properties of multiple objects or class instances all at once with one line of code?

In JavaScript (assuming version is >= ES6), say that I have a class; class MyClass { constructor() { this.property = null; } } ... and I create two new instances of the class; let inst1 = ...
user avatar
0 votes
0 answers
36 views

Create class constructor using eval: getting ReferenceError

I'm trying to create class constructor dynamically and came acrosss the following solution: https://stackoverflow.com/a/40069309/1713920 //TeamMemberProfile.js export default class TeamMemberProfile{ }...
vir us's user avatar
  • 10.5k
0 votes
0 answers
61 views

Dynamically serialise and restore ES6 class types in javascript

Is it possible to serialize ES6 class type having object instance? How? class MyClass { } let myClass = new MyClass() //store class type let clazzTypeString = serializeClassTypeToString(myClass) let ...
vir us's user avatar
  • 10.5k

15 30 50 per page
1
2 3 4 5
85