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行に次のテキスト「modulebis.worklistinitialized」をログに記録する必要があります。

4

1 に答える 1

0

Pointyが提案したとおりにしました。モジュールに name プロパティを追加し、

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