View Single Post
Old 11-13-2012, 09:13 PM   PM User | #11
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,455
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by rnd me View Post
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/

Last edited by felgall; 11-13-2012 at 09:22 PM..
felgall is offline   Reply With Quote