🗒️指令序言
两个 JavaScript 语法的全局机制:预处理和指令序言。
"use strict"; // 如果去掉这行指令,打印的结果将会变成 global
function f(){
console.log(this); // null 原封不动地被当做 this 值打印了出来,这是严格模式的特征
};
f.call(null); // 传入 null 作为 this 值"no lint"; // 比如设计一种声明本文件不需要进行 lint 检查的指令
"use strict";
function doSth(){}function doSth(){}
"use strict"; // 没有出现在最前,所以不是指令序言。
var a = 1;Last updated