Be a Supporter!

Using the "use strict" (JavaScript)

  • 674 Views
  • 3 Replies
New Topic Respond to this Topic
Rawnern
Rawnern
  • Member since: Jan. 24, 2009
  • Offline.
Forum Stats
Member
Level 28
Movie Buff
Using the "use strict" (JavaScript) Feb. 9th, 2012 @ 05:31 PM Reply

I've read a lot about the "use strict"; mode that came out not so long ago to JavaScript to optimize code. It makes it easier to make better code.

So, I decided to use the mode in all my JavaScript codes, but in JSHint, it says it have to be defined in every single function. But all I want is to be strict with my whole code. I'm comfused!

Do I have to add "use strict"; to every single function or just at the start of my .js file?

Scyllinice
Scyllinice
  • Member since: Mar. 4, 2009
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Using the "use strict" (JavaScript) Feb. 13th, 2012 @ 10:25 PM Reply

At 4 days ago, Rawnern wrote: I've read a lot about the "use strict"; mode that came out not so long ago to JavaScript to optimize code. It makes it easier to make better code.

So, I decided to use the mode in all my JavaScript codes, but in JSHint, it says it have to be defined in every single function. But all I want is to be strict with my whole code. I'm comfused!

Do I have to add "use strict"; to every single function or just at the start of my .js file?

For anyone coming across this in the future (as the OP posted this a few days ago and likely found the answer already): This suggests throwing it at the top of the file to enable it for the whole script.

Wolfos
Wolfos
  • Member since: Jan. 19, 2008
  • Offline.
Forum Stats
Member
Level 25
Game Developer
Rawnern
Rawnern
  • Member since: Jan. 24, 2009
  • Offline.
Forum Stats
Member
Level 28
Movie Buff
Response to Using the "use strict" (JavaScript) Feb. 14th, 2012 @ 02:49 PM Reply

At 16 hours ago, Scyllinice wrote: For anyone coming across this in the future (as the OP posted this a few days ago and likely found the answer already): This suggests throwing it at the top of the file to enable it for the whole script.

Thanks for your help! Exactly what I was looking for.

At 3 hours ago, Wolfos wrote: Something like this?
http://www-archive.mozilla.org/js/language/js20-2002-04/core /pragmas.html

Oh, I´ve already red that one. It´s kinda old. This rule came in 2009 etc...