XUL + javascript模块:TypeError:xxx.yyyy不是函数

时间:2015-07-08 09:03:56

标签: xul xulrunner javascript

我正在玩XUL和模块(https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Using

我已经定义了一个小模块:在hello01 / chrome / content / js / hello.jsm下

this.EXPORTED_SYMBOLS = ["Hello", "foo"];

function foo() {
  return "foo";
}

var Hello = {
  name : "bar",
  size : 3,
  incr : function()
    {
    this.size++;
    return this.size;
    },
  open : function()
    {
    return this.incr();
    }
};

此模块从hello01 / chrome / content / main.js

加载
Components.utils.import("chrome://hello/content/js/hello.jsm");

function jsdump(str) {
  Components.classes['@mozilla.org/consoleservice;1']
            .getService(Components.interfaces.nsIConsoleService)
            .logStringMessage(str);
    }

function showMore() {
  document.getElementById("more-text").hidden = false;
  jsdump("Hello!");
  jsdump(Hello.incr());
  jsdump(Hello.open());
}
来自xul窗口的

(...)
<button label="More >>" oncommand="showMore();"/>
(...)

当我点击按钮时,我会在jsconsole中看到:

Hello !
4
Error: TypeError: Hello.open is not a function
Source File: chrome://hello/content/main.js
Line: 14

为什么xul知道 Hello.incr 但不知道 Hello.open

更新:代码可在此处获取:https://github.com/lindenb/xul-bootstrap

1 个答案:

答案 0 :(得分:0)

好的,明白了:XUL-Runner在${HOME}/${VENDOR}下缓存了一些文件 它默默地忽略了我的更改并使用了缓存中的旧文件。 见XULRunner ignores updates on edited files