OAuth 的 Javascript 范围问题

发布于 2024-12-06 08:46:53 字数 1036 浏览 0 评论 0原文

我想知道如何在这一行中调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

终止放荡 2024-12-13 08:46:54
setTimeout(window.App.Something.waitForPin(scope), 100);
setTimeout(window.App.Something.waitForPin(scope), 100);
吾家有女初长成 2024-12-13 08:46:54

waitForPin 函数附加到 Something 的原型上。为了访问它,创建一个 Something 实例并调用该实例上的方法。例子

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

The waitForPin function is attached to the prototype of Something. In order to access it create an instance of Something and call the method on that instance. Example

setTimeout((new App.Something()).waitForPin, 100);
眼角的笑意。 2024-12-13 08:46:54
setTimeout(this.waitForPin, 100);

这是正确的做法。

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

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

setTimeout(this.waitForPin, 100);

That's the correct way to do it.

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

Demo: http://jsfiddle.net/bBRPv/

养猫人 2024-12-13 08:46:54

这个怎么样:

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

What about this:

setTimeout($.proxy(this.waitForPin, this), 100);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文