0

我希望能够记录我的模块初始化以查看发生了什么。有没有办法获取模块命名空间并将其记录到控制台。

(function($, bis, window, document, undefined) {
    "use strict";
    //other app code
    bis.library = bis.library || function(module) {
        $(function() {
            if (module.init) {
                module.init();
                //how can I make it log the module namespace
                console.log('module' + module.toString() + 'initialized');
            }
        });
        return module;
    };

    //other app code
})(jQuery, window._bis = window._bis || {}, window, document);

我的模块定义示例

(function($, bis, window, document, undefined) {
    "use strict";
    var common = bis.common,
        urls = bis.urls,
        defaults = bis.defaults,
        createWorklist = bis.createWorklist,
        editWorklist = bis.editWorklist,
        editMoveBoxesWorklist = bis.editMoveBoxesWorklist;

    bis.worklist = bis.worklist || bis.library((function() {
        // module variables
        var init = function() {
            //module init code
        };

        //other module code

        return {
            init: init
        };
    })());
})(jQuery, window._bis = window._bis || {}, window, document);​

因此,我希望行 console.log 记录以下文本“模块 bis.worklist 已初始化”。

4

1 回答 1

0

我按照Pointy的建议做了。我在我的模块中添加了一个 name 属性,只需使用

console.log(module.name);
于 2012-11-02T10:54:31.280 回答