本文介绍了JSLint“超出范围”功能排序导致的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSLint似乎对功能排序很挑剔。

JSLint seems to be picky about function ordering.

这好转:

function a() {
    'use strict';
    return 1;
}

function b() {
    'use strict';
    a();
}

虽然这给出了'a'不在范围错误消息:

While this gives an 'a' is out of scope error message:

function b() {
    'use strict';
    a();
}

function a() {
    'use strict';
    return 1;
}

这是设计的吗?我应该关心吗?如何避免在较大(较复杂)的情况下避免给函数一个明确的顺序?

Is this by design? Should I care? How can it be avoided in larger (more complex) cases, where it might not always be possible to give the functions a clear order?

推荐答案

JSLint / JSHint希望您在引用它们之前定义函数。但是,JavaScript并不关心,因为。

JSLint/JSHint expect you to define functions before you reference them. However, JavaScript doesn't care because functions and variables are hoisted.

您可以使用

/* jshint latedef:nofunc */
function b() {
    'use strict';
    a();
}

function a() {
    'use strict';
    return 1;
}

参见

这篇关于JSLint“超出范围”功能排序导致的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 03:38