Jshintは、モジュールパターンを明らかにする際に「未定義の」警告を投げる

StackOverflow https://stackoverflow.com/questions/8907910

質問

Jshintでこのコードを実行すると、いくつかの「未定義の」エラーが発生しています。

MERLIN.namespace('MERLIN.http');

MERLIN.http = function ($, window) {
    'use strict';
    // import dependencies

    function request(config) {
        if (!config || typeof config !== 'object') {
            return;
        }
        // perform request
        $.ajax({
            type: config.type || 'GET',
            url: config.url,
            dataType: config.dataType,
            data: config.data || {},
            processData: config.process || false,
            beforeSend: function () {
                indicator(config.panel, config.indicator);
            },
            complete: function () {
                indicator(config.panel, config.indicator);
            },
            success: function (resp) {
                var callback = config.success || null;
                if (typeof callback !== 'function') {
                    callback = false;
                }
                if (callback) {
                    callback.apply(this, [resp]);
                }
            },
            error: function (xhr, textStatus, errorThrown) {
                httpError({
                    xhr: xhr,
                    status: textStatus,
                    error: errorThrown,
                    panel: config.panel
                });
            }
        });
    };

    function indicator(panel, type) {
        if ((!panel || typeof panel !== 'string') || (!type || typeof type !== 'string')) {
            return;
        }
        var indicatorType = (type === 'large') ? type = 'indicatorLarge' : type = 'indicatorSmall';
        return $(panel).toggleClass(indicatorType);
    };

    function httpError() {
        return this;
    };

    return {
        request: request,
        error: httpError
    };

} (jQuery, this);

未定義のエラーが「インジケーター」と「httperror」にスローされている理由と、「これを返す」の使用が潜在的な厳格違反である理由はわかりません。汎用名空間関数は別のファイルで早期に定義されるため、名前空間に関連する未定義のエラーを安全に無視できることを知っています。

それは単なるプラグマティズムと厳格な検証のケースですか?

ありがとう :)

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top