Why is this code fine:
var test = {
fn1: function(_origin, _componentType) {
if(arguments.length > 1) throw "xx";
// this strict is ok
"use strict";
var interface = new Object(this);
}
}
While this isn't
var test = {
fn1: function(_origin, _componentType) {
// This strict throws SyntaxError
"use strict";
if(arguments.length > 1) throw "xx";
var interface = new Object(this);
}
}
I know interface is reserved word in strict mode, but shouldn't both examples throw an error?
StrictMode is a tool for highlighting potential problems in an application. Like Fragment , StrictMode does not render any visible UI. It activates additional checks and warnings for its descendants. Note: Strict mode checks are run in development mode only; they do not impact the production build.
The "use strict" Directive The purpose of "use strict" is to indicate that the code should be executed in "strict mode". With strict mode, you can not, for example, use undeclared variables. All modern browsers support "use strict" except Internet Explorer 9 and lower: Directive.
First, all of your code absolutely should be run in strict mode. Core modern javascript functionality is changed (see . call() and apply()) or disfigured (silent Errors) by executing code outside of strict mode.
"use strict";
needs to be the first statement in a function (or in a script, if script-wide) to trigger strict mode; anywhere else, you may as well be writing "merry christmas";
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With