简体   繁体   English

节点Javascript类方法重写

[英]node Javascript class method override

I have an node library and want to override a method in it but i don't understand how this particular object structure works. 我有一个节点库,想覆盖其中的一个方法,但是我不明白这个特殊的对象结构是如何工作的。

function MyObject(){
    this.init();
}
MyObject.prototype.init = function(){
    // tons of other stuff
    function myMethod(){
         // stuff I want to override
    }
}

Overriding the init function would be pointless because there is too much stuff in there. 覆盖init函数将毫无意义,因为其中包含太多东西。
I could just edit the lib but that's dirty and I want to prevent that if possible. 我只可以编辑该库,但是它很脏,如果可能,我想阻止它。
I tired all sorts of stuff but it didn't seem like i got it right. 我厌倦了各种各样的事情,但似乎我做对了。 Is it even possible? 可能吗?

myMethod is a "private" method of the init function, you can't get a reference to it from outside. myMethod是init函数的“私有”方法,您无法从外部获得对其的引用。 So if you don't have control over the code defining this (you say you don't want to edit the lib), you can't override the method. 因此,如果您无法控制定义此代码的代码(您说不想编辑该库),则无法覆盖该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM