【问题标题】:Access prototype function within a prototype function在原型函数中访问原型函数
【发布时间】:2013-12-31 02:04:03
【问题描述】:

我正在尝试调用原型中定义的 login 函数,但进行调用的函数 (refresh) 也在原型中。

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() {

        }
};

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

【问题讨论】:

  • 知道了,谢谢。 @Barmar

标签: javascript function prototype prototype-programming


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    这很简单:使用this.login()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      相关资源
      最近更新 更多