Quote:
Originally Posted by rnd me
with(){}
|
has been removed from strict JavaScript as being inefficient and unnecessary. Any code you could write using a with statement can be written without the with statement without any signigficant change to the number of characters the code will contain.
For example:
Code:
<script type="text/javascript">
"use strict";
with (document.getElementById('something').style) {
backgroundColor = '#ccc';
color = '#f00';
}
</script>
would simply give a syntax error because
with is no longer a valid JavaScript command. You'd need to use the following instead in order for the code to actually run (which excluding all the spaces is just one character longer):
Code:
<script type="text/javascript">
"use strict";
var d = document.getElementById('something').style;
d.backgroundColor = '#ccc';
d.color = '#f00';
</script>
Also
eval() works differently in strict JavaScript because it is no longer allowed to interact with variables outside of the eval itself.