javascript - this._get 不是一个函数 - javascript oop 和原型(prototype)

标签 javascript oop prototype

我正在使用类似于 NodeJS 的 bondi,它是基于 Firefox js 引擎构建的。基本上我收到了这个错误,我相信这是由于我在 .Get 函数中引用“this”的方式造成的下面。

基本上有一个名为 SFtpClient 的工具。它具有“获取”方法,用于列出文件夹的内容,但我想通过包含文件来更改此原型(prototype)。我需要改变它,以便它 a/失败时重试多次,b/具有递归文件夹列出功能。

因此我使用原型(prototype)对其进行了更改 - 将 .Get 移至 ._Get。

谁能明白为什么我会收到错误:

Jan 23 04:51:34 beta bondi: === this._Get is not a function --- Prio(6) Result(0x0) File(/home/nwo/approot/include/sftpclientenh

当我运行下面的代码时? 谢谢

SFtpClient.prototype._Get = SFtpClient.prototype.Get;
SFtpClient.prototype.Get = function(Folder, Retries){

    //defaults
    if(!Retries) Retries = 5;
    if(!Folder) Folder = "~/";

    //vars
    var FileListing = [];

    var connect = function(){ 
        //TODO JRF 19.01.2012 : re-enable this when bondi is fixed
        // this.HomeDirectory.replace(/\/?$/, "/");
        FileListing = this._Get(Folder);

        return true;
    }

    var i = 1;
    do{
       var res = false;
       try {
        res = connect();
       }catch(e){
           Debug.LogInfo(e.message); 
       }
       i++;
       Server.Sleep(i*2000);
    } while(res==false && i < Retries);

    return FileListing;
}

最佳答案

尝试使用 res = connect.call(this) 而不是 res = connect()

关于javascript - this._get 不是一个函数 - javascript oop 和原型(prototype),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8967378/

相关文章:

javascript - 如何从javascript函数访问 Angular $scope

javascript - 一次只允许一个用户编辑内容

c++ - 哎呀概念-得到意想不到的结果

javascript - 破解 "undefined"对象的 Javascript 定义

c++ - 为什么这个参数顺序在 regex_match 的原型(prototype)中?

javascript - 我们应该使用 .prototype 而不是当前的实例化方法吗?

javascript - JQuery DataTable - 搜索完全匹配

javascript - 带有 typescript 的 AngularJS : this resolved differently in service and config constructor

oop - 学习/实现设计模式(针对新手)

PHPOO : Overriding properties of abstract class