【问题标题】:Use strict is enforced even though it's not present in code强制使用严格,即使它不存在于代码中
【发布时间】:2019-06-06 20:37:59
【问题描述】:

我正在尝试在我的 typescript 模块中访问 function.arguments,但出现错误:

'arguments' properties may not be accessed on strict mode functions

即使'use strict' 也不存在于编译文件中。

这是我的 tsconfig.json 设置:

    "noImplicitUseStrict": true,
    "alwaysStrict": false,
    "strict": true,

如果我删除"noImplicitUseStrict": true,编译后的文件将有use strict,所以设置在打字稿端正常工作(可能?)。

搜索我的编译文件,我找不到包含“严格”一词的单个文件。

我使用节点编译js文件:node src/index.js

【问题讨论】:

  • 呃,既然可以直接访问arguments 对象,为什么还要使用function.arguments? (尽管在 ES6 中你更可能只使用 rest 参数)
  • 模块和类是严格的。可能还有其他地方。

标签: javascript typescript es6-modules strict


【解决方案1】:

ES6 模块以严格模式执行。

来自 MDN Other differences between modules and standard scripts

另外,请注意,您可能会从 脚本在模块中定义,而不是在标准脚本中。这 是因为模块自动使用严格模式。

【讨论】:

    猜你喜欢
    • 2015-05-06
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    • 2011-05-26
    • 1970-01-01
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    相关资源
    最近更新 更多