[英]How to override function/value in a class thats has been extended
A little confused on how to over ride a return value in a function.关于如何覆盖函数中的返回值有点困惑。
Example.例子。
class Customer {
getFirstName() {
return this.firstName;
}
}
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.我的目标是如果从客户调用getFirstName
,那么它将返回一个值。 If however getFirstName
is called from Client, I want it to return null
.但是,如果从客户端调用getFirstName
,我希望它返回null
。
class Client extends Customer {
//TODO
}
How would I go about this?我该怎么办?
just override and return null in client class只需在客户端类中覆盖并返回 null
class Client extends Customer {
getFirstName() {
return null
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.