繁体   English   中英

JavaScript错误,无法识别功能……为什么?

[英]Javascript error, not recognizing function… why?

这是我的代码(在Firefox插件中)

this.something_something = function (the_actual_url) {
    this.this_version = null;
    try {
        // Firefox 4 and later; Mozilla 2 and later
        Components.utils.import("resource://gre/modules/AddonManager.jsm");
        AddonManager.getAddonByID("parasites@maafire.com", function (addon) {
            this_version = addon.version;
        });
    }
    catch (ex) {
        // Firefox 3.6 and before; Mozilla 1.9.2 and before
        var em = Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager);
        var addon = em.getItemForID("parasites@maafire.com");
        this_version = addon.version;
    }


    this.timervar = setTimeout(function () {
        this.get_plugin_version(this.this_version);
    }, 2000);
}

this.get_plugin_version = function (blah) {
    alert("aa:" + blah);
}

我收到错误:

错误:this.get_plugin_version不是函数源文件:chrome://mf_monkey_project/content/overlay.js行:476

我究竟做错了什么?

抱歉搞砸了格式,但我删除了大部分代码以适合此处,这使格式化变得很麻烦。

因为setTimeout回调将在全局上下文中执行。

method to bind the desired context and argument for the callback. 您可以使用bind() 方法为回调绑定所需的上下文和参数。

this.timervar=setTimeout( this.get_plugin_version.bind(this, this.this_version),
                          2000 );

如果您不希望this.this_version的当前值永久绑定为第一个参数,则将其从.bind()调用中删除。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM