JSLint似乎对函数排序很挑剔.
这很好:
function a() {
'use strict';
return 1;
}
function b() {
'use strict';
a();
}
Run Code Online (Sandbox Code Playgroud)
虽然这给出了一条'a' is out of scope错误消息:
function b() {
'use strict';
a();
}
function a() {
'use strict';
return 1;
}
Run Code Online (Sandbox Code Playgroud)
这是设计的吗?我应该关心吗?如何在更大(更复杂)的情况下避免这种情况,在这种情况下,可能无法始终为函数提供明确的顺序?
JSLint/JSHint 希望您在引用函数之前定义它们。然而,JavaScript 并不关心,因为函数和变量都是提升的。
您可以更改代码样式,或使用http://jshint.com/docs/options/#latedef告诉 linter 忽略它
/* jshint latedef:nofunc */
function b() {
'use strict';
a();
}
function a() {
'use strict';
return 1;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3384 次 |
| 最近记录: |