This tag is for questions regarding Classes in Ecmascript 6. The tag is only for classes provided in the Ecmascript version.
Questions tagged [es6-class]
1259 questions
-2
votes
1 answer
How to convert this ES6 class React code to function format
I am a beginner in React and only know how to use functions in React, but a lot of codes around are using class. How can I convert this to a function?
Also can someone explain why they use classes? I hate the syntax.
import React from…

Alixsep
- 382
- 2
- 3
- 13
-2
votes
2 answers
Use cases for static methods
What will be all good practical and frequent use cases for using static methods in ES6 classes?
Let me add one. React has concept of compound components.
class Toggle extends React.Component {
static On = ({on, children}) => (on ? children :…

HalfWebDev
- 7,022
- 12
- 65
- 103
-2
votes
3 answers
ES6 Function result is showing NaN
I have make a ES6 class function, I can't understand why the console result is showing NaN
class Person {
constructor(firstName, lastName, dob) {
this.firstName = firstName;
this.lastName = lastName;
this.birthday =…

Niran Yousuf
- 83
- 1
- 9
-2
votes
1 answer
Making a new ES6 Object in another Object's constructor fails
Edit: this question is different from How to extend a class without having to using super in ES6? - although the answers are related, this is very obviously a different question. It relates to a specific error, and the two main classes involved…

mikemaccana
- 110,530
- 99
- 389
- 494
-2
votes
1 answer
class export returning empty object
I have an Errors class that I'm exporting using module.export.
When I require the class in another file using const Errors = require('errors.js'); and then try and use throw Errors.NotImplimented I get an undefined error at the start of throw.
If I…

Alexis Tyler
- 1,394
- 6
- 30
- 48
-2
votes
1 answer
SyntaxError: Block-scoped declarations in node.js webstorm
I am very much new to ES6, and have wrote a sample class code in node.js using webstorm ide.
'user strict';
class PersonClass {
constructor(name) {
this.name = name;
}
sayName() {
console.log(this.name);
}
}
let…

JN_newbie
- 5,492
- 14
- 59
- 97
-2
votes
1 answer
JavaScript ES6 side nav issue when function call
I'm building a side nav with JavaScript ES6 and I started with the Supercharged-Show code example. I made a toggle button to replace the show and the hide ones. I try to use my toggleSideNav function to call the showSideNav but nothing happen. I'm…

Hugo
- 163
- 4
- 16
-3
votes
1 answer
Issue in export and import ES6 Classes in protractor testing
I'm facing two issues while using ES6 class export and import. First, while import, methods cannot be accessible from imported class. Second, while executing the code through visual studio code im facing the following error "SyntaxError: Unexpected…

Murali
- 23
- 2
- 8
-3
votes
2 answers
addEventListener inside constructor es6 class get fired ones on init and never agian
I'm new to es6 classes and cant quite understand why the following behaves like it does:
let scrollElement = document.querySelector(".foo");
scrollElement.addEventListener("scroll", logSomething());
logSomething(){
console.log("hi");
…

Merijndk
- 1,674
- 3
- 18
- 35
-3
votes
1 answer
from jQuery to es6 - how to write simple plugin?
I watched Ryan Christiani's tutorials but I can't use it in practice.. :/
For example how to write this code in es6? I would like to know the best practices (class, events etc.)
var defaultOptions = {
activeClass: '.active',
tabClass: …

JanuszFrontEnd'u
- 451
- 6
- 14
-4
votes
4 answers
From an array of Car instances how to filter such items by e.g. year and model?
Hi guys I have pushed a class/object into an array like below:
class AllCar {
constructor(){
this.carList=[]
}
addCar(newCar){
this.carList.push(newCar)
}
}
class Car {
constructor(name, year, model) {
this.name = name;
…
-4
votes
1 answer
Compare Array of Objects with Object in ES6
so basically I want to compare the object of array with another object and change its value. The data is fully dynamic so I can't use static keys.
here is my data
this new DATA is the one I want to add in the invoiceDATA
but the problem is that…

Owais Ahmed Khan
- 218
- 1
- 4
- 12
-4
votes
1 answer
Ajax jquery class with es6
I need to write down class which will do ajax request in jquery variables: -contentType-form/other,
default form -method - get from attr(method)
if form or from data(method) if other -data -url- get from attr(action)
if form or from data(action)…

Bartek Mikołajczuk
- 1
- 1
- 5
-6
votes
1 answer
How do I create a class in JS using ES6 conventions?
I have a class "dog" and want its prototype to be a new class, animal. How do I create this in JS using ES6 syntax?

alexcode
- 1
- 2