Node.js将函数内的函数调用为回调函数

时间:2014-03-18 20:23:32

标签: javascript node.js oop asynchronous callback

所以,我想要以下结构:

var _class = function() {};

_class.prototype.checkThis = function(callback) {
    console.log('this');
};

_class.prototype.checkThat = function(callback){
    console.log('that');
};

_class.prototype.validate = function(callback){
    var self = this;
    this.checkThis(function(err) {
        if(!err) self.checkThat(callback);
    });
}

var inst = new _class;

inst.validate();

不幸的是,“this”并未指向“checkThis”回调中的“class”,因此“checkThat”未知。 有什么想法吗?

0 个答案:

没有答案
相关问题