我正在使用类似于 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/