es6-class Questions

3

Solved

I have a Vue.js project that use one method in multiple files, so I create an utility class to write this method there, something like: export class Util{ doSomething(){ return 'something' } } ...
Aitch asked 27/8, 2019 at 15:6

2

I want to unit test some ES6 classes that are stored as modules. However, when I try to run my tests, import triggers an error message: Cannot use import statement outside a module which means I ca...
Ummersen asked 24/5, 2020 at 12:17

5

Solved

Here is the thing. I have a main class called A. I want this class to extend class B. class A extends B {} But in fact, I want the class B to extend C, D or E on a specific condition: class B e...
Leipzig asked 4/3, 2017 at 18:16

4

Solved

Let's say you're developing a polyfill and don't want to shim a class if it already exists in the browser. How can this be done in ES6? The following is not valid because exports is not a statement...
Independent asked 20/9, 2016 at 0:26

2

Solved

I want to be able to proxy all methods of a class inside the constructor of a class itself. class Boy { constructor() { // proxy logic, do something before each call of all methods inside class ...
Quaquaversal asked 6/11, 2021 at 1:34

5

Solved

JavaScript's class syntax, added in ES6, apparently makes it legal to extend null: class foo extends null {} new foo(); Some Googling reveals that it was suggested on ES Discuss that such declara...
Takao asked 16/12, 2016 at 17:6

3

I have a dependency that is a singleton class like so: // dependency.js class Dependency { foo() { ... } } export default new Dependency(); I'm trying to mock this class with Jest but since its...
Observatory asked 17/7, 2019 at 17:16

16

Solved

I'm having the following TypeScript class export class Vehicule extends TrackableEntity { vehiculeId: number; constructor() { super(); return super.proxify(this); } } my typescript target ...
Constitutionalism asked 3/7, 2019 at 12:55

2

Solved

class TestObject { constructor(value) { if (value === null || value === undefined) { throw new Error('Expect a value!'); } } } describe('test the constructor', () => { test('it works', ()...
Chaos asked 12/10, 2017 at 10:30

1

I am trying to import an ES6 module with CoffeeScript. The javascript working code is the following : import { MyModule } from 'my-module'; const mymod = new MyModule({ some-options: '...' }); ...
Wanderjahr asked 20/6, 2018 at 11:16

2

Solved

Using ES6 class syntax, is it possible to create a new instance of the current class from the parent? For example: class Base { withFoo() { return new self({ foo: true }); } } class Child exte...
Slipway asked 10/2, 2017 at 14:31

2

Solved

I have a class using ES6 private fields and public getters that I need to be reactive using Vue 3's composition API. Currently, my set up looks something like this: //store.ts class Store { #userN...
Malanie asked 9/8, 2021 at 17:3

9

Solved

I want create object factory using ES6 but old-style syntax doesn't work with new. I have next code: export class Column {} export class Sequence {} export class Checkbox {} export class ColumnF...
Tarmac asked 2/8, 2015 at 21:45

3

Solved

The Udacity ES6 training has a question about overriding a base class constructor. I've got a solution but Udacity doesn't let me get away with it. The assignment is: Create a Bicycle subclass th...
Dorise asked 19/4, 2019 at 10:2

3

I'm using Webpack to import a javascript file that has a single class. my_class.js console.log('hello from my_class'); class myClass { // ... } index.js import './my_class.js'; webpack.config.j...
Xylograph asked 18/2, 2021 at 3:18

10

Solved

In ECMAScript 6 the typeof of classes is, according to the specification, 'function'. However also according to the specification you are not allowed to call the object created via the class synta...
Vinaya asked 17/3, 2015 at 7:22

4

Solved

I am new to React and i am very confused and continuously thinking about it day and night and almost all my hairs are fallen and still falling down, that why we always extends React.Component class...
Nomo asked 1/10, 2018 at 6:46

3

Solved

I'm using the documentation package, but cannot figure out how to get it to document class properties (that aren't defined via getters and setters). As the following just generates class documentat...
Papp asked 22/7, 2018 at 17:55

4

Solved

I'm fairly new to JS classes, and am doing mostly back-end work. I was playing around with the new JS classes and so I started going through the examples here: https://developer.mozilla.org/en-US/d...
Patrolman asked 7/11, 2016 at 17:26

6

Solved

Thanks for reading my post I get this error on my code : "Class extends value # is not a constructor or null" Here is my code, I'm trying to export/import classes. monster.js : const miniMonster ...
Fated asked 16/4, 2018 at 10:14

3

Solved

I'm in a weird situation that i need to instantiate a new Class with a string stored in a variable but even i'm sure the class name is correct i get an error that given class name is not a construc...
Infanta asked 1/3, 2018 at 4:8

7

Solved

I have a JavaScript ES6 class that has a property set with set and accessed with get functions. It is also a constructor parameter so the class can be instantiated with said property. class MyClas...
Sheepshanks asked 8/2, 2017 at 7:52

4

Solved

How would we polyfill es6 class methods into ES5? I am reading a book and it says the following: class Ninja { constructor(name) { this.name = name; } swingSword() { return true; } } is ...
Galingale asked 6/11, 2016 at 7:10

5

Solved

I want to extend native Javascript Promise class with ES6 syntax, and be able to call some asynchronous function inside the subclass constructor. Based on async function result the promise must be ...
Esmond asked 8/1, 2018 at 22:5

8

Is there any way this is possible in ES6 -- or is there a nice solution if it isn't (as seems likely): class Parent { constructor() { console.log(this.name); } } class Child extends Parent { ...
Privatdocent asked 2/4, 2019 at 16:27

© 2022 - 2025 — McMap. All rights reserved.