对此进行了一些搜索,但没有找到任何确切的信息。请考虑以下示例:
function ConstructIt (param) {
"use strict";
// Set up the object
}
我的问题与以下每种情况有关:
场景 1:在与上面相同的文件中,我们有以下代码:
ConstructIt.prototype.methodOne = function (fudgeFactor) {
// Is this still going to be in strict mode due to having it in the constructor above?
// Or must I include it here as well?
}
或 --> 场景 2:在单独的文件中,与场景 1 相同的代码(显然可以在构造函数之前或之后:
ConstructIt.prototype.methodOne = function (fudgeFactor) {
// Is this still going to be in strict mode due to having it in the constructor above?
// Or must I include it here as well?
}
简而言之,我想了解的是如何“使用严格”;影响代码,以及在哪里。另一个好问题:为什么 JSHint 建议只使用“函数