OAuth 的 Javascript 范围问题
我想知道如何在这一行中调用 waitForPin
:
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
}
};
I was wondering how to call waitForPin
in this line:
setTimeout(this.waitForPin, 100);
File:
// 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
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
waitForPin
函数附加到Something
的原型上。为了访问它,创建一个Something
实例并调用该实例上的方法。例子The
waitForPin
function is attached to the prototype ofSomething
. In order to access it create an instance ofSomething
and call the method on that instance. Example这是正确的做法。
演示:http://jsfiddle.net/bBRPv/
That's the correct way to do it.
Demo: http://jsfiddle.net/bBRPv/
这个怎么样:
What about this: