Ext.: http://ourjs.com/detail/52f572bf4534c0d806000024
"Use strict" is a very good feature in JavaScript and is very easy to work with.
How to use
File.js
"Use Strict"
function Dostuff () {
Use Strict is enabled here!
}
Such Tiao file.js will be applied to the "use strict" mode.
If you want to use only one function:
File.js
function A () {
"Use strict";
Use strict are enabled in the this context
function Nestedfunction () {
And here too
}
}
Benefits
Check for duplicate keys in an object
var zombie = {
eyeleft:0,
Eyeright:1,
... a lot of keys ...
Eyeleft:1
}
This code throws an error because Eyeleft appears two times. It's much quicker than looking for a mistake with your eyes.
Variable not declared
plane = 5;
You now know that you forgot to add var before this variable. However, if you do not know, debugging is very painful, because this variable is declared in the global context, and may be removed elsewhere. Imagine that if you declare a global I, it can cause confusion in nested loops.
Duplicate parameters
function Run (Fromwhom, Fromwhom) {}
Note that fromwho appears two times and therefore throws an error.
Arguments in a restricted function
var run = function (Fromwhom) {
Arguments[0] = ' alien ';
alert (Fromwhom);
}
Run (' zombie ');
Alert: ' Alien ';
Now you can use the "using strict"
var run = function (Fromwhom) {
"Use strict";
Arguments[0] = ' alien ';
alert (Fromwhom);
}
Run (' zombie ');
Alert: ' Zombie ';
Arguments[0] = ' alien ' changed the parameters Fromwhom,use strict and saved your time.
Original address: webdesignporto.com
Why using "use strict" can save you time