简体   繁体   English

如何覆盖已扩展的类中的函数/值

[英]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.

相关问题 如何搜索具有相应文本的特定字符串值 - How to search for specific string value thats has corresponding text 初始化后如何覆盖jQuery.ajax成功函数? - How to override the jQuery.ajax success function after it has been initialized? 如何检查值是否已传递给javascript函数 - How to check if a value has been passed on to a javascript function or not Javascript:一旦“类/对象”被“扩展”,是否可以使用不同的基“类/对象”重新扩展它? - Javascript: Once a 'class/object' has been 'extended', is it possible to re-extend it using a different base 'class/object'? 如何实例化返回扩展类的函数的结果? - How to instantiate the result of a function that returns an extended class? 打字稿特征实现:如何让通用知道它已被扩展? - Typescript Trait Implementation: how to let generic know it has been already been extended? 如何从扩展的casperjs函数返回值? - How to return value from an extended casperjs function? 如何在扩展组件上覆盖className? - How to override className on extended component? 如何覆盖具有静态功能的功能 - How to override a function that has static function JavaScript 如何从一个 function 中获取目标值并乘以已选中复选框的元素值 - JavaScript how to take target value from one function and multiply by element value for which the checkbox has been checked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM