How Is Javascript's Strict Mode Implemented
Solution 1:
It's probably because browser consoles use eval()
, which changes things. Although putting "use strict";
at the start of a string of code that is passed to eval()
works as expected, it's possible that console implementations prepend code to the string you've typed into the console, meaning that "use strict";
is no longer the first statement executed and is therefore ignored.
There's a reference to this and a suggested workaround in the following article:
http://javascriptweblog.wordpress.com/2011/05/03/javascript-strict-mode/
The suggested workaround is to wrap code in the console within a function that is immediately executed:
(function() {
"use strict";
nonExistentVariable = 1; // Error is now thrown
})();
Solution 2:
Maybe this article can help you to understand more. Anyway the solution is the one you mention, the error is because access to arguments.caller and arguments.callee throw an exception in strict mode. Thus any anonymous functions that you want to reference will need to be named.
Post a Comment for "How Is Javascript's Strict Mode Implemented"