Domanda

According the this http://caniuse.com/use-strict 'use strict' does not support in IE version 8/9.

My question is, Is it really safe to use 'use strict' in IE 8/9 or browsers that its not compatible with? Will it break my code?

È stato utile?

Soluzione

The statement "use strict"; will should not cause problems with IE8/9 insofar as the browsers will run the code. (It was designed that way, to ensure that there are no problems with browsers that don't implement strict mode)

External source: http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/

This means that you can turn strict mode on in your scripts – today – and it’ll have, at worst, no side effect in old browsers.

NOTE: as Jeremy pointed out in the comments, there are some expressions which are technically valid but will fail in IE8 (for example: var x = {}; x.break = true will not work in IE8 even though it will work in IE9).

Altri suggerimenti

Yeah, it should be fine.

use directives are meant to be backwards-compatible. Browsers that don't support them will just see a String literal that isn't referenced further. So, they'll pass over it and move on.

Though, you'll still want to be sure that you test your code both with and without it enabled.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top