Classes Flashcards

(8 cards)

1
Q

What is public property?

A

Property which will be available in the instance of the class

class A {
    public test = 1
}

It’s equals:

class A {
    test = 1
}

But it’s better to explicitly show public properties

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is private property?

A

Property which will be available only in the scope of particular class

class A {
private _test = 1

testSome() {
    console.log(this._test)
} }

Usually private properties started with _ preffix

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is class implements?

A

interface ITest {
some: string
}

class A implements ITest {
some: string
}

Helps to type a class to allow it to have some required properties or methods from an interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is protected property?

A

Property which will be available in particular class, or in child classes, but not in instances

class A {
protected a = 1
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is static property?

A

This is a property which is exist only as a property of a class

class A {
static test = 1
}

console.log(A.test)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is abstract class?

A

This is a class which can’t create instance, and can be used only for inheritance

abstract class A {
test() {
console.log(123)
}
}

const b = new A() - !!! will throw an error !!!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is readonly property?

A

This property cannot be changed

class A {
readonly some: number
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is decorators?

A

Is a function that is applied to a class, method, property, or parameter to change its behavior or add additional functionality.

Started with “@” symbol.

We can add unlimited amount of decorators.

Decorators are initialized from top to bottom. But executed from bottom to top

How well did you know this?
1
Not at all
2
3
4
5
Perfectly