2011-09-26 99 views
1

我想知道如何调用waitForPin在这一行:的Javascript范围问题的OAuth

setTimeout(this.waitForPin, 100); 

文件:

// namespace our code 
window.App = {}; 

// my class (no Class.create in JQuery so code in native JS) 
App.Something = function() { 
}; 

// add functions to the prototype 
App.Something.prototype = { 

    // automatically called 
    initialize: function(name, sound) { 

     this.wnd; 

     this.config = { 
      // some vars 
     }; 

     this.oauth = new OAuth(this.config); 

     // attach event handlers, binding to 'this' object 
     $("#request_token").click($.proxy(this.request_token, this)); 

    }, 

    request_token: function() { 
     this.oauth.fetchRequestToken(this.openAuthoriseWindow, this.failureHandler); 
    }, 

    openAuthoriseWindow: function (url) { 
     this.wnd = window.open(url, 'authorise'); 
     setTimeout(this.waitForPin, 100); // how to call waitForPin here? 
    }, 

    waitForPin : function (scope) { 
     // do sth 
    } 

}; 
+0

什么问题,这是正确的? –

回答

0
setTimeout(window.App.Something.waitForPin(scope), 100); 
0

waitForPin功能连接到的Something原型。为了访问它,创建一个Something的实例并调用该实例上的方法。例如

setTimeout((new App.Something()).waitForPin, 100); 
0
setTimeout(this.waitForPin, 100); 

这是正确的方式去做。

var Q = new App.Something; 
Q.openAuthoriseWindow(); 

演示:http://jsfiddle.net/bBRPv/

0

这个怎么样:

setTimeout($.proxy(this.waitForPin, this), 100);