[英]Javascript: call method itself inside a method (with original parameters)
i develop a class to upload a file to imageshack. 我开发了一个课程,将文件上传到imageshack。 For this you have to do a authorization first to get a auth_id.
为此,您必须先进行授权才能获得auth_id。
Because of i use this in nodejs i don't want to create the auth_id every time i upload a image. 因为我在nodejs中使用了这个,所以我不想每次上传图像时都创建auth_id。 For that i need something like this:
为此,我需要这样的东西:
function test(){
this.auth = "";
}
// Callback will execute when file-upload is finish
test.prototype.upload = function(file, callback) {
if(this.auth == "") {
/*** HERE I NEED HELP: ***/
this.make_auth(this.upload(file,callback));
}else{
// Do upload and then
callback();
}
}
test.prototype.make_auth = function(callback) {
// Make auth...
this.auth = "01020312032";
callback();
}
What i want to do: - Check if this.auth is set - If this.auth == "" make the auth and call the upload-function again after finish with the original parameters 我要做什么:-检查是否设置了this.auth-如果this.auth ==“”进行身份验证,并在使用原始参数完成后再次调用上载函数
How i can do this? 我该怎么做?
Change: 更改:
this.make_auth(this.upload(_paramters));
To something like: 像这样:
var self = this;
this.make_auth(function() { self.upload(_paramters); });
You should probably be passing a possible err
to your callback in make_auth
in case authentication fails. 万一验证失败,您可能应该在
make_auth
中的回调中传递一个可能的err
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.