The fact that this
inside a function called in the global context will not point to the global object can be used to detect strict mode:
var isStrict = (function() { return !this; })();
Demo:
> echo '"use strict"; var isStrict = (function() { return !this; })(); console.log(isStrict);' | node
true
> echo 'var isStrict = (function() { return !this; })(); console.log(isStrict);' | node
false
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…