Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在原型函数中访问原型函数_Javascript_Function_Prototype_Prototype Programming - Fatal编程技术网

Javascript 在原型函数中访问原型函数

Javascript 在原型函数中访问原型函数,javascript,function,prototype,prototype-programming,Javascript,Function,Prototype,Prototype Programming,我试图调用原型中定义的登录函数,但调用函数(刷新)也在原型中 function Checker() { var self = this; self.refresh(); window.setInterval(function(){self.refresh()}, 1000); } Checker.prototype = { refresh: function() { if(some condition)

我试图调用原型中定义的登录函数,但调用函数(刷新)也在原型中

function Checker() {
        var self = this;
        self.refresh();
        window.setInterval(function(){self.refresh()}, 1000);

}
Checker.prototype = {

        refresh: function() {
             if(some condition){
                 login(); // this won't work, neither self.login();
             }
        },
        login: function() {

        }
};

如何在刷新函数中调用登录函数?

从原型方法,实例设置为
this
。因此,
this.login()
就是您想要的。

通过原型方法,实例被设置为
this
。所以
this.login()
就是你想要的。

很简单:使用
this.login()

很简单:使用
this.login()
明白了,谢谢@巴马戈特,谢谢@巴尔马