Questions tagged [class-fields]
55 questions
1
vote
2 answers
Stubbing class field-functions in ES7
In my test suite, how can I stub a class' property, which is a function*? With normal methods it's easy using Object.getOwnPropertyNames(component.prototype) and monkey patching each found method, but after a long time of struggle I haven't found…

jalooc
- 1,169
- 13
- 23
0
votes
1 answer
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.
This works fine:
@Input()…

Brian Davis
- 745
- 1
- 11
- 14
0
votes
1 answer
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()
{
UpdateTextPlanes();
…

ahiyantra
- 1
- 2
- 4
0
votes
0 answers
How can I configure jshint to recognize special class method syntax?
I'm not sure the exact name of this syntax but this is what I use as needed:
handleChange = (event) => {
JSHint is giving me an error as it does not recognize it:
I'm not sure but I think I can set the ES version as follows:
{
"esversion": (put…

howard
- 234
- 1
- 11
0
votes
2 answers
How to get private properties names of a class in javascript?
Introduction
In order to get the properties of a class instance we can just use the Object.getOwnPropertyNames() method like in the following example
class People {
constructor(name, age) {
this.name = name;
this.age = age;
}
…

AlexSp3
- 2,201
- 2
- 7
- 24
0
votes
1 answer
How to initialize private property of a class for a test
I'm trying to write a test using JEST to a class I wrote with static properties that resembles the following:
class DataManager {
static #data = null;
static getData = () => {
return this.#data;
}
static initializeData =…

Ohad Yeahhh
- 191
- 1
- 10
0
votes
1 answer
class method doesn't override class field
Very weird behaviour. Why does the following log "A.fn" only, the next line "B.fn" doesn't even run? What exactly is happening in this following code?
I'm using Babel stage-2, which is used in most React projects.
class A {
fn = () => {
…

Maria
- 3,455
- 7
- 34
- 47
-1
votes
1 answer
Do static members of a class get initialized even before static constructor gets called?
I was reading MSDN Documentation and there seems to be a contradiction.
Static members are initialized before the static member is accessed
for the first time and before the static constructor, if there is one,
is called.
also in the next…

SamuraiJack
- 5,131
- 15
- 89
- 195
-2
votes
3 answers
Can async functions be in class fields?
Consider the following snippet:
class Foo {
method = () => {
console.log('method');
}
}
const f = new Foo();
f.method();
Works just fine. But, if the function is made async instead, with no other changes:
class Foo {
method =…

Snow
- 3,820
- 3
- 13
- 39
-3
votes
1 answer
Different ways to initialize class field with parameter
What other ways are there to initialize the class field "fieldList" based on a given List object?
One way would be Parameterized constructor.
class ObjectA {
private List fieldList;
// 1. Parameterized constructor
public…

Mihai Socaciu
- 155
- 2
- 12