61 questions
4
votes
1
answer
93
views
I expect my User Class to have an internal recursion error using accessors but it didn't. Why?
Before we begin, I'm running on a webpack-dev-server, and I'm building a to do list app. My goal is to improve my understanding of how accessors behave so that I can standardizing my writing style ...
1
vote
2
answers
101
views
How do you extend a superclass property object in a subclass in JavaScript and get TypeScript to not complain?
Given this code:
class Foo {
data = { x: 1 };
}
class Bar extends Foo {
override data = { ...super.data, y: 1 };
}
TypeScript complains on the super.data part:
Class field 'data' defined by the ...
0
votes
0
answers
61
views
Fields in Scala Constructor
I was wondering if there are any differences between the two following class implementations:
class Days(days:AnyVal):
val n: AnyVal = days
and
class Days(val n:AnyVal)
Does n has the same ...
0
votes
1
answer
116
views
Create callable objects with private properties without arguments.callee
By callable object I mean an object that's also a function similar to jQuery.
There's plenty of resources for doing this, such as this article.
However problem arise when I try to implement private ...
1
vote
2
answers
110
views
Setting property in class via parent constructor doesn't set property
Considering the following code
class A {
a;
constructor() { console.log(2); this.inv(); }
inv() { console.log(4); this.a = "a value"; }
}
class B extends A {
b;
constructor(...
4
votes
2
answers
403
views
Override getter with field works, but not vice-versa? [duplicate]
In the following code, the base class has four properties: a getter, a field, and a couple of methods that prints out the values of the other two.
In the subclasses, the base getter can be overridden ...
0
votes
1
answer
99
views
How to set an arrow-style function as a default parameter for Input()
So I have a component that displays rows of data in a table. I have an input for the function that should run if someone double clicks a row. I want to default that to doing something with the router.
...
5
votes
2
answers
6k
views
Cannot read private member from an object whose class did not declare it...?
In this program:
class Example {
#privateMember = 123;
// these are fine
addNumber (n) { return this.#privateMember + n; }
doAddNumber (n) { return this.addNumber(n); }
// "cannot ...
3
votes
1
answer
515
views
Clone private fields of class to implement immutable pattern
I'm trying to use JS classes with private fields for a React app (because I still find it weird to use naked Object instances everywhere). React uses the concept of immutable state, so I have to clone ...
2
votes
1
answer
3k
views
Can a child class overwrite a private field inherited from a superclass?
I'm playing around with ES6 classes in JavaScript and I'm wondering if it's possible for a child class to inherit private properties/methods from a superclass, while allowing the subclass to mutate ...
2
votes
1
answer
151
views
Why do extended classes uses prototypes for methods but not for fields?
Looking at this simple code :
class Animal {
someField = 42;
animalFunc() {
console.log('animal')
}
}
class Lion extends Animal {
lionFunc() {
console.loge('lion')
}...
0
votes
1
answer
235
views
Why is the private int variable in this c# program not updating?
Here's the program:
[SerializeField] ARPointCloudManager mArPointCloudManager;
private int numPointsUpdated = 0;
// Start is called before the first frame update
void Start()
{
...
8
votes
1
answer
2k
views
Access private members from developer console?
Before, I would use the old convention of naming fields intended to be private with an _ suffix or prefix.
class X{
constructor() {
this.privateField_;
}
privateMethod_() {}
}
Now that ...
4
votes
2
answers
2k
views
Why does ESLint not recognize my class arrow functions?
I followed the advice on How do I configure ESLint to allow fat arrow class methods which states to set the parser to babel-eslint.
I installed it and updated my config file as follows:
{
"...
4
votes
1
answer
903
views
Unexpected token "=" reported while running eslint on arrow functions
I have a JavaScript class and inside it I have an async method which looks like below.
class ABC {
func = async () => { //----line 10
//some code
}
func2 = () => { //----line ...