A little confused on how to over ride a return value in a function.
Example.
JavaScript
x
6
1
class Customer {
2
getFirstName() {
3
return this.firstName;
4
}
5
}
6
and I have another class that extends the above class. What I am aiming to do is if getFirstName
is called from Customer, then itll return a value. If however getFirstName
is called from Client, I want it to return null
.
JavaScript
1
4
1
class Client extends Customer {
2
//TODO
3
}
4
How would I go about this?
Advertisement
Answer
just override and return null in client class
JavaScript
1
6
1
class Client extends Customer {
2
getFirstName() {
3
return null
4
}
5
}
6