【发布时间】:2011-07-05 06:36:06
【问题描述】:
如果我们的 html 文件(导入外部 js 文件)已经有“use strict”,是否需要在外部 js 文件中加上“use strict”?
如果我们的外部 js 文件没有“use strict”,那么它们在具有“use strict”的 HTML 文件中是否仍然“严格”?
例子:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script>
"use strict";
function f() {
// calling File1 functions (File1 does not have "use strict"; at the top)
// are the File1 functions "strict"?
}
</script>
<script src="File1.js"></script>
<script>
//by the way.. is it strict here ?
</script>
</head>
<body>
</body>
</html>
【问题讨论】:
-
为什么不呢?您是否担心 15 个字节左右?
-
你完全误解了我的问题
-
呃,我的评论试图探究为什么你甚至需要知道。在任何地方都使用严格以使其更便携。 15 个字节左右不会杀死你,所以为了清楚起见,使用它。
标签: javascript