Search

12/03/2014

javascript - Is there any way to check if strict mode is enforced? - Stack Overflow

javascript - Is there any way to check if strict mode is enforced? - Stack Overflow

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; })();
> echo '"use strict"; var isStrict = (function() { return !this; })(); console.log(isStrict);' | node
true
> echo 'var isStrict = (function() { return !this; })(); console.log(isStrict);' | node
false

沒有留言: