Questions tagged [use-strict]

According to Mozilla Developer Network, ECMAScript 5's strict mode is a way to opt in to a restricted variant of JavaScript. Strict mode isn't just a subset: it intentionally has different semantics from normal code.

According to Mozilla Developer Network, ECMAScript 5's strict mode is a way to opt in to a restricted variant of JavaScript. Strict mode isn't just a subset: it intentionally has different semantics from normal code.

100 questions
11
votes
2 answers

Is this a Chrome bug or is my use of "use strict" and eval invalid?

This code works alerts "ok" in all browsers except Chrome: eval("var outer = 0; function test() {'use strict'; outer = 1; } test(); alert('ok');"); (Try it on jsfiddle). All I'm doing is referencing an outer variable from a 'use strict' function,…
Dan Abramov
  • 264,556
  • 84
  • 409
  • 511
11
votes
2 answers

Global variables in JavaScript strict mode

A simple Javascript question, For instance I have an Angular app.js like this; 'use strict'; var eventsApp = angular.module('eventsApp',[]); I read that using "use strict" in beginning of a Javascript file makes all vars in that file to be…
Spring
  • 11,333
  • 29
  • 116
  • 185
11
votes
1 answer

YUI Compressor and "use strict" hint

I've beeing using YUI Compressor to minify JS files. I have this code: (function(global) { "use strict"; var X=1; /*** my code here ***/ }(window)); And I compress it with this command: $> java -jar yuicompressor-2.4.7.jar test.js…
Guumaster
  • 389
  • 3
  • 10
9
votes
2 answers

How to set 'use strict' globally with JSLint

I'm new to javascript and am trying to validate through JSLint. Where should I put "use strict" to use it globally and validate? This gives me error "Unexpected expression 'use strict' in statement position.": "use strict"; …
Sluggo
  • 597
  • 1
  • 9
  • 21
9
votes
2 answers

Is it safe to use 'use strict' in IE 8/9

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?
Shabith
  • 3,005
  • 3
  • 23
  • 20
9
votes
1 answer

"use strict" causes undefined error

I am defining the following function in my JavaScript: function _snr(id) { "use strict"; this.e = "something"; } I ran my code through JSLint and it suggested that I add "use strict" to the function. When I do e now throws and undefined…
ferics2
  • 5,241
  • 7
  • 30
  • 46
9
votes
2 answers

What's the proper way to use jQuery in conjunction with 'use strict'?

If I have something like the following "use strict"; $(document).ready(function () { }); I get the warning '$'is not defined
deltanovember
  • 42,611
  • 64
  • 162
  • 244
8
votes
2 answers

Why doesn't "use strict" (JavaScript) detect an undeclared variable?

I'm trying to get the "use strict"; directive to work, and having a bit of trouble. In the following file FireFox 9 will (correctly) detect that someVar hasn't been declared on line 3, but fails to detect that theVar hasn't been declared on line…
MikeTheTall
  • 3,214
  • 4
  • 31
  • 40
8
votes
2 answers

Why is this illegal in strict mode?

Yeah, yeah, I know, strict mode ain't around yet, but really, I'm planning for the future... So, why is this: $('#'+ $(this).attr('id').replace('control-', 'legend-')).fadeIn(); ... not allowed in ES5 Strict mode? Or am I misinterpreting?…
Félix Saparelli
  • 8,424
  • 6
  • 52
  • 67
8
votes
0 answers

Does "use strict" offer any speed improvements?

Leaving aside possible differences stemming from code structure changes to conform with "use strict";, does running code in strict mode offer any speed benefits?
Etheryte
  • 24,589
  • 11
  • 71
  • 116
7
votes
3 answers

John Resig's simple class instantiation and "use strict"

Reference : http://ejohn.org/blog/simple-class-instantiation/ // makeClass - By John Resig (MIT Licensed) function makeClass(){ return function(args){ if ( this instanceof arguments.callee ) { if ( typeof this.init == "function" ) …
Jeeyoung Kim
  • 5,827
  • 8
  • 44
  • 54
7
votes
2 answers

How is strict mode ("use strict";) inherited by functions?

Here is my code that seems to indicate that the answer is yes - http://jsfiddle.net/4nKqu/ var Foo = function() { 'use strict' return { foo: function() { a = 10 alert('a = ' + a) } } }() try { …
Lone Learner
  • 18,088
  • 20
  • 102
  • 200
7
votes
1 answer

Why does JSLint give strict violation error on this function?

JSLint gives me the "strict violation" error, although I use the "this" context inside a function which hides it from the global scope. function test() { "use strict"; this.a = "b"; } For the record, I use the built-in JSLint parser in…
Erik Bergstedt
  • 912
  • 10
  • 27
7
votes
1 answer

Is "Bad Line Breaking" obsolete with "use strict"?

Please assume 'use strict'; and also assume that, JSLint is on and errors cannot be ignored. I find operators and ',' initiated lists so much more readable, e.g.: var i = 0 , j = 1 , someLongVariablename1 , someLongVariablename2 ,…
Ron Wertlen
  • 830
  • 10
  • 24
7
votes
4 answers

"use strict" only in debug?

I wonder if there is really nessesary to include the "use strict" when I am done programming and release my JavaScript document to anyone to see. I like to use it because to check that I have coded in a good way. So, should I include or just remove…
user1431627
  • 815
  • 3
  • 13
  • 30