14

次の単純なコードを実行すると、「厳密な違反」が発生します。エラーメッセージ。私はその理由とそれを修正する方法についてのドキュメントを見つけようとしてきました。どんな入力でも大歓迎です。

エラー:

Error:

Problem at line 6 character 4: Strict violation.

} (this));

サンプルコード:

/*jslint browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, strict: true, newcap: true, immed: true */

"use strict";

(function (window) {
} (this));

よろしく、エギル。

4

2 に答える 2

17

Roland Illigの答えを拡張するには:

非厳密モードでthisは、他にバインドされていないときにグローバルスコープにバインドされます。厳密モードでは、未定義です。そのため、メソッドの外部で使用するとエラーになります。

于 2012-02-14T07:52:00.163 に答える
8

jslintのソースコードを見てみました。

function reservevar(s, v) {
    return reserve(s, function () {
        if (this.id === 'this' || this.id === 'arguments' ||
                this.id === 'eval') {
            if (strict_mode && funct['(global)']) {
                warning("Strict violation.", this);
            } else if (option.safe) {
                warning("ADsafe violation.", this);
            }
        }
        return this;
    });
}

jslintはthis、グローバルコンテキストで使用していると本当に不満を言っていると思います。

于 2010-07-24T08:09:04.077 に答える